Skip to content

Fix GH-8235: iterator_count() may run indefinitely - #8447

Closed
cmb69 wants to merge 1 commit into
php:PHP-8.0from
cmb69:cmb/gh8235
Closed

cmb69 wants to merge 1 commit into
php:PHP-8.0from
cmb69:cmb/gh8235

Conversation

@cmb69

@cmb69 cmb69 commented Apr 27, 2022

Copy link
Copy Markdown
Member

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.

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.
@cmb69 cmb69 linked an issue Apr 27, 2022 that may be closed by this pull request
@cmb69

cmb69 commented Apr 27, 2022

Copy link
Copy Markdown
Member Author

@goodevilgenius, would that solve the issue for you? If you're running a 64bit PHP, probably not, but I wouldn't know how we could address that. After all, you can't know whether an iterator is infinite or not. Adding some arbitrary limit (say, at most 1,000,000 elements) would be possible, but … arbitrary. Introducing some INI setting appears to be overkill for that edge case. Maybe the documentation should clarify?

@goodevilgenius

Copy link
Copy Markdown

@cmb69 Sounds pretty reasonable, I suppose. On a 64-bit system, I imagine that would probably run an extremely long time before the overflow occurs. I imagine max_execution_time might be reached before the overflow even occurs. This probably takes care of the rare edge case in which someone has disabled max_execution_time, for example when running from command line.

I posted the bug as a long shot that it could even reasonably be fixed, and this sounds like the best possible solution, in any case.

@cmb69

cmb69 commented Apr 28, 2022

Copy link
Copy Markdown
Member Author

Thanks for the feedback!

Yeah, on 64bit systems the script would run for a very long time. Say the script would run for 1sec on 32bit, and all else being equal, the script would run on 64bit for several thousand years.

max_execution_time should stop the script (with or without this patch).

@cmb69 cmb69 closed this in ad7b9f4 May 3, 2022
@cmb69
cmb69 deleted the cmb/gh8235 branch May 3, 2022 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iterator_count runs indefinitely if iterator doesn't complete

2 participants