Skip to content

Commit d4ff572

Browse files
committed
Fix GH-11121: ReflectionFiber segfault
1 parent 6bb536e commit d4ff572

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

Zend/zend_fibers.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ ZEND_API void zend_fiber_switch_context(zend_fiber_transfer *transfer)
388388

389389
zend_observer_fiber_switch_notify(from, to);
390390

391+
if (from->kind == zend_ce_fiber) {
392+
zend_fiber_from_context(from)->execute_data = EG(current_execute_data);
393+
}
394+
391395
zend_fiber_capture_vm_state(&state);
392396

393397
to->status = ZEND_FIBER_STATUS_RUNNING;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
GH-11121: Segfault when using ReflectionFiber
3+
--FILE--
4+
<?php
5+
function f() {
6+
Fiber::suspend();
7+
}
8+
9+
function g() {
10+
(new Fiber(function() {
11+
global $f;
12+
var_dump((new ReflectionFiber($f))->getTrace());
13+
}))->start();
14+
}
15+
16+
$f = new Fiber(function() { f(); max(...[1,2,3,4,5,6,7,8,9,10,11,12]); g(); });
17+
$f->start();
18+
$f->resume();
19+
20+
?>
21+
--EXPECTF--
22+
array(3) {
23+
[0]=>
24+
array(7) {
25+
["file"]=>
26+
string(%d) "%sReflectionFiber_bug_gh11121_1.php"
27+
["line"]=>
28+
int(10)
29+
["function"]=>
30+
string(5) "start"
31+
["class"]=>
32+
string(5) "Fiber"
33+
["object"]=>
34+
object(Fiber)#3 (0) {
35+
}
36+
["type"]=>
37+
string(2) "->"
38+
["args"]=>
39+
array(0) {
40+
}
41+
}
42+
[1]=>
43+
array(4) {
44+
["file"]=>
45+
string(%d) "%sReflectionFiber_bug_gh11121_1.php"
46+
["line"]=>
47+
int(13)
48+
["function"]=>
49+
string(1) "g"
50+
["args"]=>
51+
array(0) {
52+
}
53+
}
54+
[2]=>
55+
array(2) {
56+
["function"]=>
57+
string(9) "{closure}"
58+
["args"]=>
59+
array(0) {
60+
}
61+
}
62+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
--TEST--
2+
GH-11121: Segfault when using ReflectionFiber
3+
--FILE--
4+
<?php
5+
6+
function f() {
7+
Fiber::suspend();
8+
}
9+
10+
function g() {
11+
(new Fiber(function() {
12+
global $f;
13+
var_dump((new ReflectionFiber($f))->getTrace());
14+
}))->start();
15+
}
16+
17+
$f = new Fiber(function() { f(); g(); });
18+
$f->start();
19+
$f->resume();
20+
21+
?>
22+
--EXPECTF--
23+
array(3) {
24+
[0]=>
25+
array(7) {
26+
["file"]=>
27+
string(%d) "%sReflectionFiber_bug_gh11121_2.php"
28+
["line"]=>
29+
int(11)
30+
["function"]=>
31+
string(5) "start"
32+
["class"]=>
33+
string(5) "Fiber"
34+
["object"]=>
35+
object(Fiber)#3 (0) {
36+
}
37+
["type"]=>
38+
string(2) "->"
39+
["args"]=>
40+
array(0) {
41+
}
42+
}
43+
[1]=>
44+
array(4) {
45+
["file"]=>
46+
string(%d) "%sReflectionFiber_bug_gh11121_2.php"
47+
["line"]=>
48+
int(14)
49+
["function"]=>
50+
string(1) "g"
51+
["args"]=>
52+
array(0) {
53+
}
54+
}
55+
[2]=>
56+
array(2) {
57+
["function"]=>
58+
string(9) "{closure}"
59+
["args"]=>
60+
array(0) {
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)