-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-19577: avoid integer overflow when using a small offset and PHP_INT_MAX with LimitIterator #19585
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
base: PHP-8.3
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather say that overflowing should throw in the constructor. And perhaps .offset
should also be zend_ulong
.
(Why is |
I guess there's a historical reasoning behind. Should it be refactored? I agree with you, but I'm afraid this kind of bug is used as a feature. |
It's not explicitly documented, but given the default values, I consider this a feature: https://www.php.net/manual/en/limititerator.construct.php I just wanted to complain without expecting any changes (that's why that remark was in parentheses). |
I just found out that there another test with a similar test case: https://github.com/php/php-src/blob/7e5ad5caf8e249453a84b4f62565188cf69b877f/ext/spl/tests/gh18421.phpt. Throwing in the constructor means that the OOB exception becomes a ValueError (like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to extract the logic into a helper function?
… PHP_INT_MAX with LimitIterator
c18c3b7
to
fd3ef91
Compare
I pushed a new version with your suggestion @Girgias, is that what you had in mind? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wasn't really understanding what the computations were doing, so now with a function it's clear :)
Fix #19577
This introduce subtraction-based comparison instead of error-prone addition.