Free the hooked property value when json_encode() sees an exception - #22919
Open
iliaal wants to merge 1 commit into
Open
Free the hooked property value when json_encode() sees an exception#22919iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
php_json_encode_array() reads a hooked property into a local zval and bails out when an exception is pending. The get hook can publish its return value into that zval and then throw while its frame is freed, for example from the destructor of one of its locals, so the bailout leaks the value until request shutdown. Destroy it on the way out, the way the other failure exit already does. Closes phpGH-22919
iliaal
force-pushed
the
fix/json-hooked-prop-exception-leak
branch
from
July 29, 2026 12:49
56e50e4 to
9de3544
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A get hook can publish its return value into the zval json_encode() handed to zend_read_property_ex(), then throw while the engine tears the hook's frame down, for instance from the destructor of one of its locals. php_json_encode_array() returns on EG(exception) without destroying that zval, so the value survives to request shutdown. Twenty encodes of a hook returning a 1 MiB string retain 21 MB before the patch, 1.5 KB after.