From 9764502cb825ed24800d03faa14361572adb7d2b Mon Sep 17 00:00:00 2001 From: srayuth Date: Sun, 25 Oct 2026 23:16:29 +0700 Subject: [PATCH] Report delayed OOM raised during compilation even when compilation fails 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 GH-24631. --- Zend/tests/gh24631.phpt | 32 ++++++++++++++++++++++++++++++++ Zend/zend.c | 11 +++++++++++ 2 files changed, 43 insertions(+) create mode 100644 Zend/tests/gh24631.phpt diff --git a/Zend/tests/gh24631.phpt b/Zend/tests/gh24631.phpt new file mode 100644 index 000000000000..8a667a67c16a --- /dev/null +++ b/Zend/tests/gh24631.phpt @@ -0,0 +1,32 @@ +--TEST-- +GH-24631: Delayed OOM raised during compilation is reported even when compilation fails +--SKIPIF-- + +--FILE-- +&1'); +@unlink($inc); + +// The real error (OOM) must be reported, and the spurious parse error must not. +var_dump( + str_contains($out, 'Allowed memory size'), + str_contains($out, 'Parse error') +); +?> +--EXPECT-- +bool(true) +bool(false) +--CLEAN-- + diff --git a/Zend/zend.c b/Zend/zend.c index 216056511215..84b4ae5307c8 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -1981,6 +1981,17 @@ ZEND_API zend_result zend_execute_script(int type, zval *retval, zend_file_handl zend_hash_add_empty_element(&EG(included_files), file_handle->opened_path); } + /* GH-24631: a delayed OOM raised during compilation must be reported even + * when compilation produced no op_array. Any pending exception here (e.g. a + * parse error from the OOM-truncated source) is a downstream artifact of the + * OOM, so discard it and let the OOM be the reported error. */ + if (ZEND_HAS_OOM()) { + if (EG(exception)) { + zend_clear_exception(); + } + zend_handle_delayed_oom(); + } + zend_result ret = SUCCESS; if (op_array) { zend_execute(op_array, retval);