diff --git a/Zend/tests/gh22521.phpt b/Zend/tests/gh22521.phpt new file mode 100644 index 000000000000..a5e91ded5a8f --- /dev/null +++ b/Zend/tests/gh22521.phpt @@ -0,0 +1,24 @@ +--TEST-- +GH-22521: Infinite recursion inside try/catch should not crash unpredictably +--INI-- +memory_limit=8G +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Fatal error: Allowed memory size of %d bytes exhausted at %s:%d (tried to allocate %d bytes) in %s on line %d diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 2dceac2512db..16e740eec4aa 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -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; + } if (!ZEND_OP_IS_FRAMELESS_ICALL(opline->opcode)) { goto not_frameless_call; }