Repository navigation
Report delayed OOM raised during compilation even when compilation fails - #24694
srayuth089 wants to merge 1 commit into
Conversation
A delayed OOM recorded during compilation was only handled when zend_compile_file() returned an op_array. If compilation then failed (e.g. a parse error on the OOM-truncated source), the pending EG(delayed_oom) was dropped and the parse error reported instead of the real out-of-memory error. Handle it regardless of whether an op_array was produced, discarding the downstream parse-error exception in favour of the OOM. Fixes phpGH-24631.
|
Quoted below: written with Claude, an LLM, as CONTRIBUTING.md asks us to mark. The builds and test runs behind it are on my machine; the commands to repeat them are under the fold.
|
Fixes GH-24631.
A delayed OOM recorded while compiling the main script is only consumed by
zend_execute_script()whenzend_compile_file()returns an op_array. When compilation fails afterwards — e.g. the OOM-truncated source yields a parse error —op_arrayisNULL,zend_handle_delayed_oom()is never reached, and the pendingEG(delayed_oom)is silently dropped: the parse error is reported instead of the real out-of-memory error.This mirrors the gap @bhaak noted for
sapi/fuzzer/fuzzer-sapi.c, where the sameif (op_array)guard hides a compile-time OOM.Fix
Handle the delayed OOM right after
zend_compile_file(), regardless of whether an op_array was produced. A pending exception at that point (the parse error from the truncated source) is a downstream artifact of the OOM, so it is discarded in favour of the OOM, which is the real error.Reproduce
php -n -r 'file_put_contents("oom.php", "<?php\n\$a = \x27" . str_repeat("A", 3 << 19) . "\x27;\n)\n");' php -n -d memory_limit=4M oom.phpBefore:
After:
Testing
Zend/tests/gh24631.phpt.master(8.7.0-dev): case A (huge literal + stray)) now reports only the OOM; a clean huge literal still reports the OOM; an ordinary parse error (no OOM) is unaffected.Zend/testsrun: 0 failed, 0 warned (175 skipped for the minimal--disable-all --enable-clibuild, 1 expected-fail).