Skip to content

Zend: Reset extended_value of FREE synthesized by DCE - #25836

Closed
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/aph-zend-dce-free-extended-value-dhtt-84-work
Closed

iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/aph-zend-dce-free-extended-value-dhtt-84-work

Conversation

@iliaal

@iliaal iliaal commented Nov 27, 2026

Copy link
Copy Markdown
Member

If a destructor run by a FREE that DCE synthesized throws, cleanup_live_vars() frees the operand a second time. DCE turns a dead instruction whose operand still needs freeing into a FREE but keeps the old extended_value. After a (float) or (array) cast or empty(), that value has bit 0 set, which ZEND_HANDLE_EXCEPTION reads as ZEND_FREE_ON_RETURN. The test pins opcache.jit=disable because function JIT has a separate destructor-timing bug in the same code, caused by result_may_be_separated().

@arnaud-lb arnaud-lb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Did you want to target 8.4 ?

@iliaal
iliaal force-pushed the fix/aph-zend-dce-free-extended-value-dhtt-84-work branch from 34b7e70 to 7b44256 Compare November 27, 2026 15:16
@iliaal
iliaal changed the base branch from master to PHP-8.4 November 27, 2026 15:16
@iliaal

iliaal commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Yes, retargeted to 8.4.

DCE rewrites a dead instruction whose operand still needs freeing into a
FREE, but kept the instruction's extended_value. After (float) and (array)
casts and empty() it has bit 0 set, which ZEND_HANDLE_EXCEPTION reads as
ZEND_FREE_ON_RETURN: when a destructor run by that FREE throws, the throw
point moves by the FREE's op2, which is (uint32_t)-1, and
cleanup_live_vars() frees the operand a second time.
@iliaal
iliaal force-pushed the fix/aph-zend-dce-free-extended-value-dhtt-84-work branch from 7b44256 to 97ee5bd Compare November 27, 2026 18:10
@iliaal iliaal closed this in 04103df Nov 27, 2026
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.

2 participants