Skip to content

[13.x] Fix Number::pairs() infinite loop when $to or $by is non-finite#60648

Open
Amirhf1 wants to merge 1 commit into
laravel:13.xfrom
Amirhf1:fix/number-pairs-infinite-loop
Open

[13.x] Fix Number::pairs() infinite loop when $to or $by is non-finite#60648
Amirhf1 wants to merge 1 commit into
laravel:13.xfrom
Amirhf1:fix/number-pairs-infinite-loop

Conversation

@Amirhf1

@Amirhf1 Amirhf1 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Number::pairs() did not guard against non-finite $to/$by values, unlike its sibling methods
(fileSize(), forHumans(), trim()) in the same class, which already handle INF/NAN safely.

This currently produces three distinct bugs:

  • Number::pairs(INF, 10) causes a fatal out-of-memory crash the loop condition $lower < $to never becomes false, so it iterates until PHP exhausts its memory limit.
  • Number::pairs(NAN, 10) silently returns an empty array (any comparison against NAN is false, so the loop body never runs).
  • Number::pairs(10, NAN) returns a bogus pair containing NAN.

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) ​

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.

1 participant