-
Notifications
You must be signed in to change notification settings - Fork 8k
Prevent int overflow on $decimals in number_format for PHP < 8.3 #11714
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
Conversation
ext/standard/math.c
Outdated
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.
You can use ZEND_LONG_INT_OVFL & ZEND_LONG_INT_UDFL which will allow you to avoid this #if and make the code a bit cleaner. These macros will resolve to false if zend_long and int are the same size.
There's also ZEND_LONG_EXCEEDS_INT, but that's unusable here because you still want to set dec_int to a sane value.
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.
updated
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.
This looks logical to me and seems to work right. If no more comments of other reviewers arrive I'll go ahead and merge.
I think this also needs to be applied to 8.1 though, but no need to change the target branch as this will require manual merging anyway and I can deal with it.
I understand the issues with the test you listed in #11649. Upon merging into 8.3 I can take your tests from that other PR.
Uh oh!
There was an error while loading. Please reload this page.
This is a follow-up PR for #11649 targeting 8.2
As #11487 is available in 8.3 only and a positive
$decimals
will most probably end up in OOM error ... I don't have a good idea how to test this