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
6 changes: 6 additions & 0 deletions ext/spl/spl_iterators.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,12 @@ static zend_object_iterator *spl_recursive_it_get_iterator(zend_class_entry *ce,
static zend_result spl_get_iterator_from_aggregate(zval *retval, zend_class_entry *ce, zend_object *obj) {
zend_function **getiterator_cache =
ce->iterator_funcs_ptr ? &ce->iterator_funcs_ptr->zf_new_iterator : NULL;
if (getiterator_cache && ((*getiterator_cache)->common.fn_flags & ZEND_ACC_ABSTRACT)) {
zend_throw_error(NULL, "Cannot call abstract method %s::%s()",
ZSTR_VAL((*getiterator_cache)->common.scope->name),
ZSTR_VAL((*getiterator_cache)->common.function_name));
return FAILURE;
}
zend_call_method_with_0_params(obj, ce, getiterator_cache, "getiterator", retval);
if (EG(exception)) {
return FAILURE;
Expand Down
42 changes: 42 additions & 0 deletions ext/spl/tests/gh25228.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
GH-25228 (Segfault in IteratorIterator::__construct() when $class is an abstract IteratorAggregate)
--FILE--
<?php

abstract class A implements IteratorAggregate {}
class B extends A {
public function getIterator(): Iterator {
return new ArrayIterator([1]);
}
}

abstract class C implements IteratorAggregate {
abstract public function getIterator(): Iterator;
}
class D extends C {
public function getIterator(): Iterator {
return new ArrayIterator([1]);
}
}

try {
new IteratorIterator(new B, 'A');
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

try {
new IteratorIterator(new D, 'C');
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

foreach (new IteratorIterator(new B, 'B') as $v) {
var_dump($v);
}

?>
--EXPECT--
Cannot call abstract method IteratorAggregate::getIterator()
Cannot call abstract method C::getIterator()
int(1)
Loading