Skip to content

Free the hooked property value when json_encode() sees an exception - #22919

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/json-hooked-prop-exception-leak
Open

Free the hooked property value when json_encode() sees an exception#22919
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/json-hooked-prop-exception-leak

Conversation

@iliaal

@iliaal iliaal commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant