You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Uninitialised opline read in zend_generator_dtor_storage() when an internal function drives a generator that throws while holding a suspended generator with finally #25929
It crashes reliably (3/3) with the PHP CLI of the dunglas/frankenphp:1.13.5-php8.5.12-bookworm Docker image (ZTS, Debian bookworm, x86_64) and our ini. A plain build of the 8.5.12 source with --disable-all --enable-zts shows the same uninitialised read under valgrind (below), so it does not depend on extensions. With php -n it happens to pass, but valgrind reports the same uninitialised read, so passing looks like luck of memory layout.
Conditions (all three needed, as far as I could narrow it down):
An outer generator throws.
At that moment one of its CVs holds a suspended inner generator that still has a pending finally (an empty finally {} is enough).
The outer generator is driven by an internal function (iterator_to_array, iterator_count, IteratorIterator). Driving it with a userland foreach is clean under valgrind.
valgrind on 8.5.12 built with -g -O2 --disable-all --enable-zts:
Conditional jump or move depends on uninitialised value(s)
at zend_generator_dtor_storage (zend_generators.c:317)
by zend_objects_store_del (zend_objects_API.c:181)
by zend_free_compiled_variables (zend_execute.c:4285)
by zend_generator_close (zend_generators.c:146)
by zend_dispatch_try_catch_finally_helper_SPEC (zend_vm_execute.h:3379)
by execute_ex
by zend_generator_resume (zend_generators.c:849)
by zend_generator_iterator_rewind (zend_generators.c:1197)
by spl_iterator_apply (spl_iterators.c:2961)
by zif_iterator_to_array (spl_iterators.c:3054)
Line 317 is:
if (EG(current_execute_data)
&&EG(current_execute_data)->opline&&EG(current_execute_data)->opline->opcode==ZEND_HANDLE_EXCEPTION) {
Here EG(current_execute_data) is the frame of the internal function iterator_to_array, whose opline is not initialised, so the check dereferences garbage. The opline->opcode check came with fb1ec9a (GH-20714), whose message notes EG(current_execute_data) may already be the parent frame; the parent being an internal frame does not seem to be covered. Guarding with ZEND_USER_CODE(EG(current_execute_data)->func->type) made the valgrind error go away in my local build, but I have not run the php-src test suite with it.
The same lines are unchanged on PHP-8.4, PHP-8.5, master and php-8.5.13 as of today.
Activity
lazerg commentedon Nov 30, 2026
Looks like #25278 already covers this with a
ZEND_USER_CODEguard inzend_generator_dtor_storage.