[GIT-PULLS] [php-src] PR #22689: Fix serialize() object lifetime across nested callbacks

[email protected] (PuH4ck3rX)
Newsgroups php.git-pulls
Message-ID <[email protected]>
Pull Request: https://github.com/php/php-src/pull/22689
Author: PuH4ck3rX

php_add_var_hash() skipped uniquely owned objects when the current class had no __serialize() or __sleep() method. However, serializing one of that object's properties can invoke a nested magic callback. The callback may release the current object while its declared-property slots are still being traversed, leaving the serializer with stale zval pointers.

The skipped object was also absent from the serialization identity table. A temporary local reference would prevent destruction but would not preserve reference semantics if a nested callback made the object reachable again. This change removes the unsafe RC1 fast path so objects are retained and registered for the full serialization operation.

The regression test deterministically replaces the released object with a same-layout object. Before the fix, serialize() emits the replacement string under the victim property name; after the fix, it preserves the original integer value.

Checks performed:

- Built PHP 8.4 with ASan and UBSan, with opcache JIT disabled.
- The new regression test and the two GH-12265 identity tests passed.
- The complete ext/standard/tests/serialize directory passed: 159 passed, 5 skipped, 0 failed.
- 4 reduced reproducer scripts completed without sanitizer findings.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.