Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
marc-mabe wants to merge 2 commits into php:PHP-8.2 from marc-mabe:82-num-format-int-overflow

Conversation

Copy link
Contributor

@marc-mabe marc-mabe commented Jul 16, 2023
edited
Loading

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

}

RETURN_STR(_php_math_number_format_ex(num, (int)dec, dec_point, dec_point_len, thousand_sep, thousand_sep_len));
#if SIZEOF_ZEND_LONG > SIZEOF_INT
Copy link
Member

@nielsdos nielsdos Jul 16, 2023
edited
Loading

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.

iluuu1994 reacted with thumbs up emoji
Copy link
Contributor Author

@marc-mabe marc-mabe Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

nielsdos reacted with thumbs up emoji
Copy link
Member

@nielsdos nielsdos left a 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.

marc-mabe reacted with thumbs up emoji
@marc-mabe marc-mabe deleted the 82-num-format-int-overflow branch June 16, 2024 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@nielsdos nielsdos nielsdos approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /