Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/spl/spl_iterators.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static inline spl_dual_it_object *spl_dual_it_from_obj(zend_object *obj) /* {{{
#define SPL_FETCH_AND_CHECK_DUAL_IT(var, objzval) \
do { \
spl_dual_it_object *it = Z_SPLDUAL_IT_P(objzval); \
if (it->dit_type == DIT_Unknown) { \
if (it->dit_type == DIT_Unknown || (!it->inner.iterator && it->dit_type != DIT_AppendIterator)) { \
zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); \
RETURN_THROWS(); \
} \
Expand Down
70 changes: 70 additions & 0 deletions ext/spl/tests/gh25415.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
--TEST--
GH-25415 (Segfault in FilterIterator::next() after the subclass catches an exception from parent::__construct())
--CREDITS--
marinelay
--FILE--
<?php

function g() { yield 1; }

$gen = g();
foreach ($gen as $v) {}

$iterators = [
new class($gen) extends FilterIterator {
public function __construct(Iterator $it) {
try {
parent::__construct($it);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
}
public function accept(): bool { return true; }
},
new class($gen) extends IteratorIterator {
public function __construct(Iterator $it) {
try {
parent::__construct($it);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
}
},
new class($gen) extends NoRewindIterator {
public function __construct(Iterator $it) {
try {
parent::__construct($it);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
}
},
];

foreach ($iterators as $it) {
foreach (['valid', 'key', 'current', 'next'] as $method) {
try {
$it->$method();
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
}
}

?>
--EXPECT--
Cannot traverse an already closed generator
Cannot traverse an already closed generator
Cannot traverse an already closed generator
The object is in an invalid state as the parent constructor was not called
The object is in an invalid state as the parent constructor was not called
The object is in an invalid state as the parent constructor was not called
The object is in an invalid state as the parent constructor was not called
The object is in an invalid state as the parent constructor was not called
The object is in an invalid state as the parent constructor was not called
The object is in an invalid state as the parent constructor was not called
The object is in an invalid state as the parent constructor was not called
The object is in an invalid state as the parent constructor was not called
The object is in an invalid state as the parent constructor was not called
The object is in an invalid state as the parent constructor was not called
The object is in an invalid state as the parent constructor was not called
Loading