[php-src] PR #21733: Fix GH-21730: Mt19937::__debugInfo() leaks state HashTable when the serialize callback fails
| From: | iliaal | Date: | Sun, 12 Apr 2026 02:24:58 +0000 |
| Subject: | [php-src] PR #21733: Fix GH-21730: Mt19937::__debugInfo() leaks state HashTable when the serialize callback fails | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35684@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21733
Author: iliaal
Fixes #21730.
Mt19937::__debugInfo() allocates a temporary HashTable with
array_init(&t) and then calls the engine's serialize callback. If
the callback returns false, the method throws "Engine serialize failed" and hits
RETURN_THROWS() before inserting t, so the HashTable leaks.
PcgOneseq128XslRr64 and Xoshiro256StarStar alias the same method and share
the leak.
Niels Dossche fixed the same pattern in __serialize() via #20383 (720e0069829). That
cleanup didn't touch __debugInfo(). The fix here is identical: insert
t into the return value before calling the callback, so RETURN_THROWS()
unwinds it cleanly on failure.
The leak path is latent in stock PHP because the three built-in serialize callbacks all
return true, so no user code reaches it today. I'm filing it for symmetry with
#20383 and to keep the pattern from regressing if a future engine grows a failing serialize path.
The new phpt (debuginfo_states.phpt) locks down the success-path output shape for all
three engines, so future refactors of this code have something to break against. The leak itself
can't be exercised from PHP without patching the source (covered in the linked issue). I
verified the fix under valgrind with a forced-failure patch: the fixed build reports zero
definitely-lost bytes.