You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
iterator_count runs indefinitely if iterator doesn't complete #8235
When an iterator never finishes, the iterator_count method simply hangs. This is in contrast to the iterator_to_array method, which throws a fatal error when it runs out of memory. Since iterator_count will continue running, and eventually overflow, no exception is thrown.
This is obviously a tricky situation. But it would be useful if there were some way to detect that an iterator is unlikely to finish, and throw an exception of some sort, rather than simply allowing the program to hang.
I've observed this behavior in multiple versions of PHP (8.0+), as well as multiple operating systems (desktop Linux, Android, and macOS)
Normally this sort of "PHP code runs for a long time without running out of memory due to some infinite loop" problem is covered by the max_execution_time setting. Does that make sense as a solution here too?
Activity
damianwadley commentedon Mar 21, 2022
Normally this sort of "PHP code runs for a long time without running out of memory due to some infinite loop" problem is covered by the
max_execution_timesetting. Does that make sense as a solution here too?cmb69 commentedon Mar 21, 2022
I think we need to bail out in case of overflow:
php-src/ext/spl/spl_iterators.c
Line 3130 in 0ba9216
While that may not happen in practice, wrapping around certainly makes no sense.
Fix phpGH-8235: iterator_count() may run indefinitely
Merge branch 'PHP-8.0' into PHP-8.1
Merge branch 'PHP-8.1'