Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  Fix GH-18322: SplObjectStorage debug handler mismanages memory
This commit is contained in:
Niels Dossche 2025-04-14 14:11:35 +02:00
commit fc63a98f17
No known key found for this signature in database
GPG key ID: B8A8AD166DF0E2E5
3 changed files with 33 additions and 4 deletions

4
NEWS
View file

@ -39,6 +39,10 @@ PHP NEWS
(nielsdos) (nielsdos)
. Fix potential leaks when writing to BIO fails. (nielsdos) . Fix potential leaks when writing to BIO fails. (nielsdos)
- SPL:
. Fixed bug GH-18322 (SplObjectStorage debug handler mismanages memory).
(nielsdos)
- Standard: - Standard:
. Fixed bug GH-18145 (php8ts crashes in php_clear_stat_cache()). . Fixed bug GH-18145 (php8ts crashes in php_clear_stat_cache()).
(Jakub Zelenka) (Jakub Zelenka)

View file

@ -336,12 +336,10 @@ static inline HashTable* spl_object_storage_debug_info(zend_object *obj) /* {{{
ZEND_HASH_FOREACH_PTR(&intern->storage, element) { ZEND_HASH_FOREACH_PTR(&intern->storage, element) {
array_init(&tmp); array_init(&tmp);
/* Incrementing the refcount of obj and inf would confuse the garbage collector.
* Prefer to null the destructor */
Z_ARRVAL_P(&tmp)->pDestructor = NULL;
zval obj; zval obj;
ZVAL_OBJ(&obj, element->obj); ZVAL_OBJ_COPY(&obj, element->obj);
add_assoc_zval_ex(&tmp, "obj", sizeof("obj") - 1, &obj); add_assoc_zval_ex(&tmp, "obj", sizeof("obj") - 1, &obj);
Z_TRY_ADDREF(element->inf);
add_assoc_zval_ex(&tmp, "inf", sizeof("inf") - 1, &element->inf); add_assoc_zval_ex(&tmp, "inf", sizeof("inf") - 1, &element->inf);
zend_hash_next_index_insert(Z_ARRVAL(storage), &tmp); zend_hash_next_index_insert(Z_ARRVAL(storage), &tmp);
} ZEND_HASH_FOREACH_END(); } ZEND_HASH_FOREACH_END();

View file

@ -0,0 +1,27 @@
--TEST--
GH-18322 (SplObjectStorage debug handler mismanages memory)
--FILE--
<?php
$stor = new SplObjectStorage();
$obj = new stdClass;
$stor[$obj] = 1;
$tmp = $stor->__debugInfo();
$tmp2 = $tmp[array_key_first($tmp)];
unset($tmp); // Drop $tmp2 RC to 1
$tmp2[0]['obj'] = new stdClass;
var_dump($tmp2);
?>
--EXPECT--
array(1) {
[0]=>
array(2) {
["obj"]=>
object(stdClass)#3 (0) {
}
["inf"]=>
int(1)
}
}