From 1e53b16cd0aa0d3fd946e838167ac81104d46e5d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 16 Nov 2026 18:09:04 +0100 Subject: [PATCH 1/2] Fix object_properties_load() with integer keys A dynamic property with an integer key is added to the property table under that integer, when unserialize() gives a string key to the properties of other objects. The property can't be read then, and clone hits an assertion in debug builds when the table is packed: $s = new SplObjectStorage(); $s->__unserialize([[], [7 => 'y']]); var_dump($s->{7}); // Undefined property clone $s; --- NEWS | 3 +++ Zend/zend_API.c | 5 ++++- ...Storage_unserialize_int_property_keys.phpt | 22 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 ext/spl/tests/SplObjectStorage/SplObjectStorage_unserialize_int_property_keys.phpt diff --git a/NEWS b/NEWS index a6555ac871c9..22a10b57511d 100644 --- a/NEWS +++ b/NEWS @@ -74,6 +74,9 @@ PHP NEWS . Fixed use-after-free when a Fiber callable resolves to $this of the method creating the Fiber ([A::class, 'm'] or "A::m") and that object dies before the Fiber runs. (Edmond Dantes) + . Fixed object_properties_load() adding integer keys to property tables, which + made the properties unreadable and clone hit an assertion. + (Nicolas Grekas) - CLI: . Fixed built-in server rejecting long request paths, or paths received in diff --git a/Zend/zend_API.c b/Zend/zend_API.c index d8ea2c5ed553..b9edd8832c37 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1798,7 +1798,10 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties) ZSTR_VAL(object->ce->name), h); } - prop = zend_hash_index_update(zend_std_get_properties_ex(object), h, prop); + /* Property tables only have string keys */ + zend_string *name = zend_long_to_str(h); + prop = zend_hash_update(zend_std_get_properties_ex(object), name, prop); + zend_string_release_ex(name, false); zval_add_ref(prop); } } ZEND_HASH_FOREACH_END(); diff --git a/ext/spl/tests/SplObjectStorage/SplObjectStorage_unserialize_int_property_keys.phpt b/ext/spl/tests/SplObjectStorage/SplObjectStorage_unserialize_int_property_keys.phpt new file mode 100644 index 000000000000..deb59b15a457 --- /dev/null +++ b/ext/spl/tests/SplObjectStorage/SplObjectStorage_unserialize_int_property_keys.phpt @@ -0,0 +1,22 @@ +--TEST-- +Integer keys in the properties that internal classes load when unserialized +--FILE-- +{7}); +var_dump(clone $storage); + +?> +--EXPECT-- +string(1) "y" +object(Storage)#2 (2) { + ["7"]=> + string(1) "y" + ["storage":"SplObjectStorage":private]=> + array(0) { + } +} From 2c85d33d3493477d30f361f88349beefcc198337 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 16 Nov 2026 18:39:19 +0100 Subject: [PATCH 2/2] Update the GMP test that expected an integer key `$g->{1} = 123` creates the property with a string key. The test expected the unserialized object to have it under an integer key. --- ext/gmp/tests/gmp_dynamic_property.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/gmp/tests/gmp_dynamic_property.phpt b/ext/gmp/tests/gmp_dynamic_property.phpt index ff3d4ac94e01..dd442043a27f 100644 --- a/ext/gmp/tests/gmp_dynamic_property.phpt +++ b/ext/gmp/tests/gmp_dynamic_property.phpt @@ -17,7 +17,7 @@ Deprecated: Creation of dynamic property GMP::$1 is deprecated in %s on line %d Deprecated: Creation of dynamic property GMP::$1 is deprecated in %s on line %d object(GMP)#%d (%d) { - [1]=> + ["1"]=> int(123) ["num"]=> string(1) "0"