Skip to content

Commit fb374f5

Browse files
committed
Rethrow exceptions in fiber destructor
We need to make sure that HANDLE_EXCEPTION is set when the fiber throws during destruction. Fixes oss-fuzz #33875.
1 parent c15dc63 commit fb374f5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Make sure exceptions are rethrown when throwing from fiber destructor
3+
--FILE--
4+
<?php
5+
$fiber = new Fiber(function() {
6+
try {
7+
Fiber::suspend();
8+
} finally {
9+
throw new Exception("Exception 2");
10+
}
11+
});
12+
$fiber->start();
13+
unset($fiber);
14+
throw new Exception("Exception 1");
15+
?>
16+
--EXPECTF--
17+
Fatal error: Uncaught Exception: Exception 2 in %s:%d
18+
Stack trace:
19+
#0 [internal function]: {closure}()
20+
#1 {main}
21+
thrown in %s on line %d

Zend/zend_fibers.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ static void zend_fiber_object_destroy(zend_object *object)
398398
zend_fiber_switch_to(fiber);
399399

400400
if (EG(exception)) {
401+
if (!exception && EG(current_execute_data) && EG(current_execute_data)->func
402+
&& ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) {
403+
zend_rethrow_exception(EG(current_execute_data));
404+
}
405+
401406
zend_exception_set_previous(EG(exception), exception);
402407

403408
if (EG(flags) & EG_FLAGS_IN_SHUTDOWN) {

0 commit comments

Comments
 (0)