Skip to content

Commit ad7b9f4

Browse files
committed
Fix GH-8235: iterator_count() may run indefinitely
We need to prevent integer overflow to eventually stop the iteration. A test case doesn't appear sensible for this, because even on 32bit architectures a respective test easily runs for a few minutes. Closes GH-8447.
1 parent 136ef6f commit ad7b9f4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ PHP NEWS
88
- FPM:
99
. Fixed ACL build check on MacOS. (David Carlier)
1010

11+
- SPL:
12+
. Fixed bug GH-8235 (iterator_count() may run indefinitely). (cmb)
13+
1114
- Zip:
1215
. Fixed type for index in ZipArchive::replaceFile. (Martin Rehberger)
1316

ext/spl/spl_iterators.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,6 +3157,9 @@ PHP_FUNCTION(iterator_to_array)
31573157

31583158
static int spl_iterator_count_apply(zend_object_iterator *iter, void *puser) /* {{{ */
31593159
{
3160+
if (UNEXPECTED(*(zend_long*)puser == ZEND_LONG_MAX)) {
3161+
return ZEND_HASH_APPLY_STOP;
3162+
}
31603163
(*(zend_long*)puser)++;
31613164
return ZEND_HASH_APPLY_KEEP;
31623165
}

0 commit comments

Comments
 (0)