From 5344bcca97bbf238fe7f4211537df258dbde794e Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Mon, 20 Jan 2025 21:41:46 +0100 Subject: [PATCH] Fix GH-17408: Assertion failure Zend/zend_exceptions.c `zend_test_create_throwing_resource` sets the exception in the `test` call frame and unwinds to `main`. It then throws for the `resource` variable and verifies that the exception opline is set. However, it wasn't set in `main`, it was set at the `test` call frame and rethrown later. The assertion is too conservative, but the end result is right, so drop the assertion. Closes GH-17533. Co-authored-by: Ilija Tovilo --- NEWS | 2 ++ Zend/zend_exceptions.c | 1 - ext/zend_test/tests/gh17408.phpt | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ext/zend_test/tests/gh17408.phpt diff --git a/NEWS b/NEWS index 1ca375ce8ba..9b1fc5f8541 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,8 @@ PHP NEWS . Fixed NULL arithmetic during system program execution on Windows. (cmb, nielsdos) . Fixed potential OOB when checking for trailing spaces on Windows. (cmb) + . Fixed bug GH-17408 (Assertion failure Zend/zend_exceptions.c). + (nielsdos, ilutov) - DOM: . Fixed bug GH-17500 (Segfault with requesting nodeName on nameless doctype). diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 11b615c214a..a4e1c2f98c6 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -193,7 +193,6 @@ ZEND_API ZEND_COLD void zend_throw_exception_internal(zend_object *exception) /* zend_exception_set_previous(exception, EG(exception)); EG(exception) = exception; if (previous) { - ZEND_ASSERT(is_handle_exception_set() && "HANDLE_EXCEPTION not set?"); return; } } diff --git a/ext/zend_test/tests/gh17408.phpt b/ext/zend_test/tests/gh17408.phpt new file mode 100644 index 00000000000..f54a7b81fce --- /dev/null +++ b/ext/zend_test/tests/gh17408.phpt @@ -0,0 +1,22 @@ +--TEST-- +GH-17408 (Assertion failure Zend/zend_exceptions.c) +--EXTENSIONS-- +zend_test +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught Exception: Throwing resource destructor called in %s:%d +Stack trace: +#0 %s(%d): test() +#1 {main} + +Next Exception: Throwing resource destructor called in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d