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
24 changes: 24 additions & 0 deletions Zend/tests/gh22521.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
GH-22521: Infinite recursion inside try/catch should not crash unpredictably
--INI--
memory_limit=8G
--SKIPIF--
<?php
if (!getenv('RUN_RESOURCE_HEAVY_TESTS')) die('skip resource-heavy test');
if (getenv('SKIP_SLOW_TESTS')) die('skip slow test');
if (PHP_INT_SIZE != 8) die('skip 64-bit only');
?>
--FILE--
<?php
try {
function foo() {
foo();
}
foo();
} catch (\Throwable $_ffl_e) {
echo "Caught throwable\n";
}
echo "End\n";
?>
--EXPECTF--
Fatal error: Allowed memory size of %d bytes exhausted at %s:%d (tried to allocate %d bytes) in %s on line %d
3 changes: 3 additions & 0 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,9 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
/* For frameless calls we add an additional frame for the call itself. */
if (ZEND_USER_CODE(call->func->type)) {
const zend_op *opline = call->opline;
if (UNEXPECTED(!opline)) {
goto not_frameless_call;
}

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.

This may be the wrong fix: A NULL opline implies that we are missing a SAVE_OPLINE() somewhere in the engine.

if (!ZEND_OP_IS_FRAMELESS_ICALL(opline->opcode)) {
goto not_frameless_call;
}
Expand Down
Loading