Fix GH-17384: Reject too large number_format decimals#22435
Open
LamentXU123 wants to merge 1 commit into
Open
Conversation
Girgias
reviewed
Jun 24, 2026
Comment on lines
+1418
to
+1421
| if (dec > INT_MAX) { | ||
| zend_argument_value_error(2, "must be less than or equal to %d", INT_MAX); | ||
| RETURN_THROWS(); | ||
| } |
Member
There was a problem hiding this comment.
Surely, to error on truncation?
Suggested change
| if (dec > INT_MAX) { | |
| zend_argument_value_error(2, "must be less than or equal to %d", INT_MAX); | |
| RETURN_THROWS(); | |
| } | |
| if (dec > INT_MAX || dec < INT_MIN) { | |
| zend_argument_value_error(2, "must be between %d and %d", INT_MIN, INT_MAX); | |
| RETURN_THROWS(); | |
| } |
Contributor
Author
There was a problem hiding this comment.
Hmm I don't think we should reject "large" negative numbers. They works fine (see: https://3v4l.org/4uI70#v) because they always returns to 0 and doesn't awkwardly allocates a whopping 2GB memories.
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_format($number, 9876543210);is now silently equals tonumber_format($number, 2147483647);and generates 2147483647 decimal places and eat up 2 GB memory (and exhaust almost half of them which cause a fatal error).I only reject very large positive numbers here (as every input larger than 2147483647 is silently turned into 2147483647). Because negative ones is always returning
0anyways and only very large positive numbers can cause to such problems.Fixes #17384