[php-src] Issue #25056: Nested unserialize() can expose an outer object while its __unserialize() data is still being parsed

From: Date: Fri, 30 Oct 2026 12:46:50 +0000
Subject: [php-src] Issue #25056: Nested unserialize() can expose an outer object while its __unserialize() data is still being parsed
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-253938@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/25056 Author: bukka ### Description A nested unserialize() call from Serializable::unserialize() shares the outer reference table. An r/R record can therefore resolve to an outer object whose __unserialize() data is still being parsed. At that point __unserialize() has not been queued and cannot be called because the outer parser frame is suspended. If inner code only stores the object, identity is preserved and it is initialized later. If it accesses the object immediately, it observes incomplete userland properties and could reach uninitialized native state for internal classes. Unlike GH-19860, this object is not fully parsed, so finishing pending callbacks at the nested boundary cannot fix this case. ### Reproducer ```php <?php class Outer { public string $value; public function __unserialize(array $data): void { $this->value = "ready"; } } class Legacy implements Serializable { public function serialize(): string { return ""; } public function unserialize(string $data): void { $object = unserialize($data); var_dump(isset($object->value)); } public function __serialize(): array { return []; } public function __unserialize(array $data): void {} } $result = unserialize("O:5:\"Outer\":1:{i:0;C:6:\"Legacy\":4:{r:1;}}"); echo $result->value, "\n"; ``` Output: ```text bool(false) ready ``` ### Expected behavior This needs a separate design decision. Rejecting these references prevents unsafe access, but breaks cyclic payloads that previously retained the object until initialization completed.

« previous php.bugs (#253938) next »