[13.x] Fix Number::pairs() infinite loop when $to or $by is non-finite#60648
Open
Amirhf1 wants to merge 1 commit into
Open
[13.x] Fix Number::pairs() infinite loop when $to or $by is non-finite#60648Amirhf1 wants to merge 1 commit into
Amirhf1 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Number::pairs()did not guard against non-finite$to/$byvalues, unlike its sibling methods(
fileSize(),forHumans(),trim()) in the same class, which already handleINF/NANsafely.This currently produces three distinct bugs:
Number::pairs(INF, 10)causes a fatal out-of-memory crash the loop condition$lower < $tonever becomes false, so it iterates until PHP exhausts its memory limit.Number::pairs(NAN, 10)silently returns an empty array (any comparison againstNANisfalse, so the loop body never runs).Number::pairs(10, NAN)returns a bogus pair containingNAN.This PR extends the existing validation in
pairs()(which already throws for$by == 0) to also reject non-finite$to/$by, consistent with how the rest of the class handles this input.Reproduction
php Number::pairs(INF, 10); // Fatal error: Allowed memory size exhausted Number::pairs(NAN, 10); // [] (silently wrong) Number::pairs(10, NAN); // [[0, NAN]] (silently wrong)