[php-src] Issue #8041: php 8.2.0-dev crashes with assertion for cloning/get_object_vars on non-empty SplFixedArray (8.1 unaffected)
| From: | TysonAndre | Date: | Mon, 07 Feb 2022 14:34:15 +0000 |
| Subject: | [php-src] Issue #8041: php 8.2.0-dev crashes with assertion for cloning/get_object_vars on non-empty SplFixedArray (8.1 unaffected) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-239538@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8041
Comment Author: TysonAndre
> 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.
Thanks for the help!
@dstogov you may want to look at https://github.com/php/php-src/pull/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
get_properties* in 8.2+)
- I think the approach in that PR would reduce memory usage, by not leaving around the property
table
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
(array) casts - var_export property fetching is implemented for SplDoublyLinkedList but
not others.
- The first time I saw this I thought the list was empty, years ago
- Requiring that the property table be built (or for get_properties to return an empty array and
hide properties, like in ext/ffi/ffi.c) also increases memory usage of data structures that *do*
support inspection with var_export.
- This would also affect PECL extensions implementing custom behavior for get_properties, or future
datastructures added to core php-src.
- php-ds also doesn't implement var_export, possibly due to initial limitations of
get_properties predating get_properties_for being introduced in php 7.4,
but it'd run into this issue because of that.
- I ran into issues like this when testing vectors in DEBUG mode in https://github.com/TysonAndre/pecl-teds/
```php
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);
{}
```