-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix GH-9186 @strict-properties can be bypassed using unserialization #9354
Conversation
439dd65
to
a5d030e
Compare
a5d030e
to
2de79fe
Compare
I'm not sure why ext/standard/tests/serialize/unserialize_ref_to_overwritten_declared_prop.phpt fails 🤔 |
https://www.php.net/Error says php > echo var_representation(serialize(new Error('', 0, new RuntimeException())));
"O:5:\"Error\":7:{s:10:\"\x00*\x00message\";s:0:\"\";s:13:\"\x00Error\x00string\";s:0:\"\";s:7:\"\x00*\x00code\";i:0;s:7:\"\x00*\x00file\";s:14:\"php shell code\";s:7:\"\x00*\x00line\";i:1;s:12:\"\x00Error\x00trace\";a:0:{}s:15:\"\x00Error\x00previous\";O:16:\"RuntimeException\":7:{s:10:\"\x00*\x00message\";s:0:\"\";s:17:\"\x00Exception\x00string\";s:0:\"\";s:7:\"\x00*\x00code\";i:0;s:7:\"\x00*\x00file\";s:14:\"php shell code\";s:7:\"\x00*\x00line\";i:1;s:16:\"\x00Exception\x00trace\";a:0:{}s:19:\"\x00Exception\x00previous\";N;}}"
|
You have some other tests to update, as well https://github.com/php/php-src/runs/7876075206?check_suite_focus=true and possibly others |
Nice, thank you for the help, I didn't notice it's private, only saw that it's declared indeed.
Yeah, I haven't yet have time to fix all the tests, I could only search for failures in a few prominent directories like Zend and ext/standard), so I'll continue later :) |
I've just fixed a bunch of tests (hopefully), but I'm unsure about what to do with |
36087c2
to
a706d6b
Compare
EDIT: You can/should use the default serialization mechanism and the alternative serialization format from serialize() is deprecated - the issue is that they need to switch to I think that switching them to implementing php 7.4 See e2ea0f1 and https://bugs.php.net/bug.php?id=77866 - It seems like the only reason other SPL classes weren't switched was because they didn't implement the deprecated ext/spl/spl_dllist.c // ext/spl/spl_fixedarray.c
PHP_METHOD(SplFixedArray, __wakeup)
{
spl_fixedarray_object *intern = Z_SPLFIXEDARRAY_P(ZEND_THIS);
HashTable *intern_ht = zend_std_get_properties(Z_OBJ_P(ZEND_THIS));
zval *data;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
if (intern->array.size == 0) {
int index = 0;
int size = zend_hash_num_elements(intern_ht);
spl_fixedarray_init(&intern->array, size);
ZEND_HASH_FOREACH_VAL(intern_ht, data) {
ZVAL_COPY(&intern->array.elements[index], data);
index++;
} ZEND_HASH_FOREACH_END();
/* Remove the unserialised properties, since we now have the elements
* within the spl_fixedarray_object structure. */
zend_hash_clean(intern_ht);
}
} |
Yes, I definitely agree.
And I agree here as well :) We should change these later, possibly including other classes as well. |
For the record, there are legit use cases for calling both these methods explicitly in userland. For __construct: 1. lazy initialization after calling ReflectionClass::newInstanceWithoutConstructor and 2. for resetting instances to some initial states. For __unserialize: implement userland serialization logic as done in eg symfony/var-exporter
If you mean to deprecate __wakeup at the engine level, aka for all classes, then I would be very cautious as implementing an alternative using __serialize/__unserialize is quite complex. __sleep/__wakeup are just fine for simple needs. |
b06b007
to
d2829e6
Compare
Yes :) #8422 and a few other PRs added support for the new serialization method in ext/date, so I think we could safely get rid of their |
After those review comments are addressed and tests pass, I think this should be ready
The latest changes to php-src should be fetched and this should be rebased to pick up e3034db for fpm test failures (Aside: Tomorrow, the target branch may need to be changed to |
Co-Authored-By: Tyson Andre <[email protected]>
032dcb1
to
817adf5
Compare
The test should be green now! 🤞
It would be awesome if this could be merged before branching. :) But now, I'm off to bed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took one last look at the entire PR and found one thing I missed - lgtm other than comment about reverting ZEND_COLD
->ZEND_API
now that it's no longer needed by ext/standard/var_unserializer.re
ext/standard/tests/serialize/serialization_objects_incomplete.phpt
Outdated
Show resolved
Hide resolved
phpGH-9354 added the `__serialize` and `__unserialize` method, so unserialize() and other unserializers will call `__unserialize` instead of `__wakeup` for SplFixedArray and userland subclasses. This targets php 8.3 because we've already released betas and release candidates for php 8.2.
A typed property of an object properties table is an indirect pointer (IS_IND) to a typed reference (IS_REF). Neither of those should be in the backing array after unserializing an SplFixedArray (see SplFixedArray::fromArray()). I missed this initially when reviewing phpGH-9354
GH-9354 added the `__serialize` and `__unserialize` method, so unserialize() and other unserializers will call `__unserialize` instead of `__wakeup` for SplFixedArray and userland subclasses. RFC: https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_splfixedarraywakeup
No description provided.