Skip to content

Commit 78a5e02

Browse files
GH-15911: prevent appending an AppendIterator to itself
1 parent 41af933 commit 78a5e02

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ PHP NEWS
7676
(ilutov)
7777
. Fixed bug GH-16479 (Use-after-free in SplObjectStorage::setInfo()). (ilutov)
7878
. Fixed bug GH-16478 (Use-after-free in SplFixedArray::unset()). (ilutov)
79+
. Fixed bug GH-15911 (Infinite recursion in AppendIterator::append()).
80+
(DanielEScherzer)
7981

8082
- Standard:
8183
. Fixed bug GH-16293 (Failed assertion when throwing in assert() callback with

ext/spl/spl_iterators.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,6 +2961,11 @@ PHP_METHOD(AppendIterator, append)
29612961

29622962
SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS);
29632963

2964+
if (Z_OBJ_P(ZEND_THIS) == Z_OBJ_P(it)) {
2965+
zend_argument_value_error(1, "must be different than the iterator being appended to");
2966+
RETURN_THROWS();
2967+
}
2968+
29642969
if (intern->u.append.iterator->funcs->valid(intern->u.append.iterator) == SUCCESS && spl_dual_it_valid(intern) != SUCCESS) {
29652970
spl_array_iterator_append(&intern->u.append.zarrayit, it);
29662971
intern->u.append.iterator->funcs->move_forward(intern->u.append.iterator);

ext/spl/tests/gh15911.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
GH-15911 (Infinite recursion when appending AppendIterator to itself)
3+
--FILE--
4+
<?php
5+
6+
$iterator = new \AppendIterator();
7+
8+
$iterator->append($iterator);
9+
?>
10+
--EXPECTF--
11+
Fatal error: Uncaught ValueError: AppendIterator::append(): Argument #1 ($iterator) must be different than the iterator being appended to in %s:%d
12+
Stack trace:
13+
#0 %s(%d): AppendIterator->append(Object(AppendIterator))
14+
#1 {main}
15+
thrown in %s on line %d

0 commit comments

Comments
 (0)