#39722 closed defect (bug) (worksforme)
wp_upload_dir() causing preg_match(): null byte in regex in wp-includes\functions.php on line 5163
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.7.1 |
Component: | Media | Keywords: | needs-patch |
Focuses: | Cc: |
Description
I initially submitted this to WooCommerce, as it initially appeared to be a big pertaining to its activation:
https://github.com/woocommerce/woocommerce/issues/13008
However, upon basic testing, it looks like the issue is caused by the wp_upload_dir()
function. For reference, this only seems to occur in a Win7 machine running XAMPP/Apache/PHP7. Testing remotely on nginx/PHP 5.6 and nginx/PHP7 LEMP CentOS servers, the issue doesn't appear (which leads me to believe it is a Windows issue).
To recreate:
function uploadDirTest() { echo '<pre style="padding-left: 10rem;">'; print_r(wp_upload_dir()); echo '</pre>'; } add_action('admin_head', 'uploadDirTest');
Results
preg_match(): null byte in regex in wp-includes\functions.php on line 5163
Call stack
#0 wp_is_stream() called at [C:\xampplite\htdocs\mysite\wp-includes\functions.php:1600] #1 wp_mkdir_p() called at [C:\xampplite\htdocs\mysite\wp-includes\functions.php:1900] #2 wp_upload_dir() called at [C:\xampplite\htdocs\mysite\wp-content\plugins\vnmAdmin\vnmAdmin.php:659] #3 uploadDirTest() called at [C:\xampplite\htdocs\mysite\wp-includes\class-wp-hook.php:298] #4 WP_Hook->apply_filters() called at [C:\xampplite\htdocs\mysite\wp-includes\class-wp-hook.php:323] #5 WP_Hook->do_action() called at [C:\xampplite\htdocs\mysite\wp-includes\plugin.php:453] #6 do_action() called at [C:\xampplite\htdocs\mysite\wp-admin\admin-header.php:142] #7 require_once(C:\xampplite\htdocs\mysite\wp-admin\admin-header.php) called at [C:\xampplite\htdocs\mysite\wp-admin\plugins.php:422]
Change History (7)
#3
in reply to:
↑ 1
@
7 years ago
- Keywords reporter-feedback added
Hi @indextwo, welcome to Trac! Thanks for the report.
Replying to indextwo:
The linked SO post suggests to me that the
$path
parameter ofwp_is_stream
is being passed null byte(s), andpreg_replace
with double quotes ("
) is trying to parse them.
The regex here includes $wrappers_re
though, not $path
, and it should not contain any null bytes. I could not reproduce the issue on Windows 7 or 10 with Apache and PHP 7.
Could you put var_dump( $wrappers_re );
before that line and see what the result is?
On my install, it's (php|file|glob|data|http|ftp|zip|compress.zlib|https|ftps|phar)
.
#4
@
7 years ago
- Keywords reporter-feedback removed
Hey @SergeyBiryukov
Well spotted - I hadn't even clocked that $path
wasn't in the preg_replace
- I just found a thing that fixed it and wiped my brow.
I've just done a var_dump
and it looks like I'm getting the exact same result as you, with the exception of compress.bzip2
:
string(78) "(php|file|glob|data|http|ftp|zip|compress.zlib|compress.bzip2|https|ftps|phar)"
...however, I've also just realised that the problem has mysteriously disappeared [insert embarrassed emoji here].
I thought it was super-odd that it appeared out of nowhere yesterday, but I assumed it might have been linked to the 4.7.2
update, which happened that morning for me. I'd tried restarting all of my services, but hadn't tried rebooting my actual computer.
It might still be worth noting that whatever caused a null byte
to get into the function, using single quotes instead of the double in the regex completely solved it.
#5
follow-up:
↓ 6
@
6 years ago
Hi peeps,
i had this issue just now after installing and running a plugin called "Regenerate Thumbnails" (https://wordpress.org/plugins/regenerate-thumbnails/)
Warning: preg_match(): Null byte in regex in functions.php on line 5219
I found that it was a permissions issue!
Navigated to the \wp-content\uploads folder and set the permissions correctly, this seemed to get rid of the error messages at least.
Hope this helps anyone in a similar situation :)
#6
in reply to:
↑ 5
@
5 years ago
- Resolution set to invalid
- Status changed from new to closed
Hello @huemanfoo , could you elaborate on how was it a permissions issue and how did you fix it? I do have the regenerate-thumbnails plugin since forever but never ran until this error until today, on my localhost only.
by the way, @indextwo looking for this error I ran into your posts many times, you were everywhere, I'm glad you fixed your problem.
Update
Haven't had time to really look into why this is happening on a Windows platform specifically, but I have found a fix:
As per this thread: http://stackoverflow.com/a/39603464/988246 I changed the return of
wp_is_stream($path)
to single quotes rather than double:return preg_match( '!^$wrappers_re://!', $path ) === 1;
The linked SO post suggests to me that the
$path
parameter ofwp_is_stream
is being passed null byte(s), andpreg_replace
with double quotes ("
) is trying to parse them.