Skip to content

Commit 5fe799a

Browse files
committed
Merge branch 'PHP-8.3'
2 parents 37f683a + d98586b commit 5fe799a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Zend/tests/generators/gh14387.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
GH-14387 (Crash when stack walking in destructor of yielded from values during Generator->throw())
3+
--FILE--
4+
<?php
5+
6+
function prime(Generator $generator) {
7+
$generator->valid();
8+
}
9+
10+
$g = (function () {
11+
yield from [null, new class {
12+
function __destruct() {
13+
// Trigger a stack walk, hitting a bad frame.
14+
throw new Exception;
15+
}
16+
}];
17+
})();
18+
19+
prime($g);
20+
21+
$g->throw(new Error);
22+
23+
?>
24+
--EXPECTF--
25+
Fatal error: Uncaught Error in %s:%d
26+
Stack trace:
27+
#0 {main}
28+
29+
Next Exception in %s:%d
30+
Stack trace:
31+
#0 %s(%d): class@anonymous->__destruct()
32+
#1 [internal function]: {%s}()
33+
#2 %s(%d): Generator->throw(Object(Error))
34+
#3 {main}
35+
thrown in %s on line %d

Zend/zend_generators.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ static void zend_generator_throw_exception(zend_generator *generator, zval *exce
466466
* to pretend the exception happened during the YIELD opcode. */
467467
EG(current_execute_data) = generator->execute_data;
468468
generator->execute_data->opline--;
469+
generator->execute_data->prev_execute_data = original_execute_data;
469470

470471
if (exception) {
471472
zend_throw_exception_object(exception);

0 commit comments

Comments
 (0)