Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Zend/tests/gh24631.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
GH-24631: Delayed OOM raised during compilation is reported even when compilation fails
--SKIPIF--
<?php
if (getenv('USE_ZEND_ALLOC') === '0') die('skip Zend MM required');
if (getenv('SKIP_SLOW_TESTS')) die('skip slow test');
?>
--FILE--
<?php
$php = getenv('TEST_PHP_EXECUTABLE');
$inc = __DIR__ . '/gh24631_inc.php';
// Huge string literal (forces OOM while compiling the file under a tight
// memory_limit) followed by a stray ')' that would otherwise produce a parse
// error on the OOM-truncated token stream.
file_put_contents($inc, "<?php\n\$a = '" . str_repeat('A', 3 << 19) . "';\n)\n");

$out = shell_exec($php . ' -n -d memory_limit=4M ' . escapeshellarg($inc) . ' 2>&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--
<?php
@unlink(__DIR__ . '/gh24631_inc.php');
?>
11 changes: 11 additions & 0 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading