-
Notifications
You must be signed in to change notification settings - Fork 7.9k
php 8.2.0-dev crashes with assertion for cloning/get_object_vars on non-empty SplFixedArray (8.1 unaffected) #8041
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
Comments
The real problem is SplFixedArray that reuses properties for something else. I'll try to take a deeper look before "fixing" the engine for one weird class. In any case, for |
Thanks for the help! @dstogov you may want to look at #6261 - that PR overrides get_properties_for instead, and I had suggestions on how to finish the implementation of that (that would overlap with possible fixes that could be implemented for get_properties, as well as be useful as a model for other data structures/PECLs to properly implement
Some context on the problem I'm trying to solve The way other data structures in the SPL is slightly unintuitive for end users the first time they run into it - e.g. SplDoublyLinkedList and it's subclasses don't implement var_export or
php > $x = new SplFixedArray(1); $x[0] = 123; var_export($x);
SplFixedArray::__set_state(array(
0 => 123,
))
php > $x = new SplDoublyLinkedList();
php > $x->push(123);
php > var_export($x);
SplDoublyLinkedList::__set_state(array(
))
php > var_dump($x);
object(SplDoublyLinkedList)#1 (2) {
["flags":"SplDoublyLinkedList":private]=>
int(0)
["dllist":"SplDoublyLinkedList":private]=>
array(1) {
[0]=>
int(123)
}
}
php > var_dump((array)$x);
array(0) {
}
php > debug_zval_dump($x);
object(SplDoublyLinkedList)#1 (2) refcount(2){
["flags":"SplDoublyLinkedList":private]=>
int(0)
["dllist":"SplDoublyLinkedList":private]=>
array(1) refcount(1){
[0]=>
int(123)
}
}
php > echo json_encode($x);
{} |
This should be fixed by c77bbcd |
Thanks, that approach seems good - it may need to be communicated to PECL authors, though. (e.g. PECL authors should conditionally call zend_hash_packed_to_hash in 8.2 EDIT: get_properties_for won't work for var_export infinite recursion detection where cyclic data structures are possible, but it's probably fine if everything's a non-object/non-array, e.g. https://github.com/TysonAndre/pecl-teds/blob/main/teds_intvector.stub.php EDIT: A note in UPGRADING.INTERNALS, probably |
Description
The following code:
Resulted in this output (in a debug build - php 8.1 is unaffected), crashes in nts build for larger arrays:
But I expected this output instead:
Similar bugs affect Zend/zend_builtin_functions.c get_object_vars()
Cause:
ZEND_HASH_MAP_FOREACH_KEY_VAL(old_object->properties, num_key, key, prop) {
expects the propertiesHashTable*
to always be associative, but it sometimes be packed, e.g. for SplFixedArray.Possible solutions:
ZEND_HASH_FOREACH_KEY_VAL
macro that works with both packed and associative HashTables. This seems to me like the best solution.@nikic @dstogov thoughts?
The following parts of the code are likely to be affected, I've only confirmed for zend_objects.c and zend_builtin_functions.c
PHP Version
PHP 8.2.0-dev (2022-Feb-05)
Operating System
No response
The text was updated successfully, but these errors were encountered: