Opened 2 years ago
Closed 22 months ago
#57121 closed defect (bug) (fixed)
'get_current_user_id' in 'gettext' filter causing memory error
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.2 | Priority: | normal |
Severity: | normal | Version: | 6.1 |
Component: | Users | Keywords: | has-patch fixed-major |
Focuses: | Cc: |
Description
I am trying to 'get_current_user_id' in 'gettext' filter and causing memory error.
Here is log of error:
2022/11/15 22:18:30 [error] 667958#667958: *8577 FastCGI sent in stderr: "PHP message: PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/server/htdocs/wp-includes/class-wp-user.php on line 521
I am not sure but this code is working on WP 5.8.6
Let me know if i can help in anything...
Attachments (1)
Change History (9)
#1
@
2 years ago
- Component changed from General to Users
- Milestone changed from Awaiting Review to 6.1.2
- Version changed from 6.1.1 to 6.1
#2
@
2 years ago
- Keywords has-patch added
57121.diff appears to work, because it succeeds in setting the static $duplicated_keys
array once and no longer goes into this code section on subsequent calls.
As a workaround until a fix is released, this can also be resolved by removing the filter before calling get_current_user_id()
and readding it after:
function my_gettext_callback( $translation ) { remove_filter( 'gettext', __FUNCTION__ ); $user_id = get_current_user_id(); add_filter( 'gettext', __FUNCTION__ ); return $translation; } add_filter( 'gettext', 'my_gettext_callback' );
#3
@
2 years ago
Writing a test for this is tricky, as wp_salt()
is called via wp_create_nonce()
in wp_default_scripts()
and wp_default_packages_inline_scripts()
as part of the general bootstrap routine before test suite initialization, so the $duplicated_keys
static variable is already set and the loop cannot be triggered by a test.
#4
@
2 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 55433:
#5
@
2 years ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for 6.1.2 consideration.
#6
@
23 months ago
- Milestone changed from 6.1.2 to 6.2.1
Moving to 6.2.1, as there are no plans for 6.1.2 at this time.
Hi there, welcome to WordPress Trac! Thanks for the report.
I was able to reproduce the issue with this code:
which displays the following call stack:
This appears to be introduced in [54249] / #55937, where a
__()
function call was added towp_salt()
.get_current_user_id()
calls thedetermine_current_user
filter, which callswp_validate_auth_cookie()
, which eventually callswp_salt()
, leading to an infinite loop.Moving to 6.1.2 to investigate potential options to fix this.