[php-src] PR #24446: Fix serialize() throwing for arrays that refer to themselves through references of refcount 1
| From: | lacatoire | Date: | Mon, 19 Oct 2026 18:35:14 +0000 |
| Subject: | [php-src] PR #24446: Fix serialize() throwing for arrays that refer to themselves through references of refcount 1 | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-39609@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/24446
Author: lacatoire
References of refcount 1 are dereferenced by
serialize() and never recorded in the
variable table, so an array that contains itself through such references recurses until the stack
limit and throws an Error. Protect against recursion only for the arrays reached
through such a reference, so that arrays shared by several objects are still written in full.
### To reproduce
```php
<?php
function mk() { $p = ["n" => "p"]; $c = ["n" => "c"];
$c["parent"] = &$p; $p["children"][] = &$c; return $p; }
echo strlen(serialize(mk())), "\n";
```
php repro.php on PHP 8.5.4
Before: Error: Maximum call stack size of 8339456 bytes (zend.max_allowed_stack_size -
zend.reserved_stack_size) reached. Infinite recursion?
After: 131