Opened 21 months ago
Last modified 5 weeks ago
#47164 new defect (bug)
map_deep in formatting.php do not handle null-byte
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | critical | Version: | 5.2.2 |
Component: | Formatting | Keywords: | has-patch |
Focuses: | Cc: |
Description
<?php foreach ( $object_vars as $property_name => $property_value ) { $value->$property_name = map_deep( $property_value, $callback ); }
The above code snippet in the function map_deep in formatting.php will trigger a fatal error if for some reason $property_name starts with a null-byte. null-bytes can exist in this context if $object_vars for some reason is from an object cast to an array. private and protected properties will be prefixed with null * null
We've encountered it in the wild with serialized objects, and even though this is because of faulty programming (child classes with stricter access for properties than the parents) wordpress should handle this.
The simples solution I can think of id to add:
<?php foreach ( $object_vars as $property_name => $property_value ) { **if (ord($property_name) === 0) { continue; }** $value->$property_name = map_deep( $property_value, $callback ); }
Attachments (1)
Change History (8)
#2
@
18 months ago
Even though this is old, it pretty much explains the problem in a short and concise way: https://cweiske.de/tagebuch/php-property-started-nul.htm
#3
@
16 months ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
Hi @bitcomplex, welcome to WordPress Trac! Thanks for the report.
Just noting that I was able to reproduce the fatal error with this code:
class Dummy { public $pub = 0; protected $prot = 1; private $priv = 2; } $test = (object) (array) new Dummy(); $test = stripslashes_deep( $test );
#5
@
10 months ago
@SergeyBiryukov what can I do to get this patched? Our site breaks for each wp update that touches formatting.php. It's no joke :(
I was pretty sure this was an issue related to a php bug patched in php7.2 ( https://bugs.php.net/bug.php?id=49649 )
But after upgrading to 7.3.7 (from 7.1.x) we get issues with this.
serialized objects fetched from db fails here. It is possible because of the objectes in the db is serialized with an old php version where the bug exists. But wp could handle it better.
Error: Cannot access property started with '\0'
#12 /home/httpd/rackesbutiken/rackesbutiken.se/wp-includes/formatting.php(4742): map_deep
#11 /home/httpd/rackesbutiken/rackesbutiken.se/wp-includes/formatting.php(2691): stripslashes_deep
#10 /home/httpd/rackesbutiken/rackesbutiken.se/wp-includes/formatting.php(5342): wp_unslash
#9 /home/httpd/rackesbutiken/rackesbutiken.se/wp-includes/meta.php(182): update_metadata
#8 /home/httpd/rackesbutiken/rackesbutiken.se/wp-includes/post.php(2061): update_post_meta