Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Apr 27, 2022

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
Copy link
Member Author

cmb69 commented Apr 27, 2022

@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

@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
Copy link
Member Author

cmb69 commented Apr 28, 2022

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