number_format() crashes with large numbers.
| Bug #27678 | number_format() crashes with large numbers. | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2004-03-24 14:27 UTC | Modified: | 2005-12-26 15:49 UTC |
|
||||||||||
| From: | morten_odegaard at broadpark dot no | Assigned: | helly (profile) | |||||||||||
| Status: | Closed | Package: | Math related | |||||||||||
| PHP Version: | 5CVS, 4CVS (2005-12-26) (cvs) | OS: | * | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2004-03-24 14:27 UTC] morten_odegaard at broadpark dot no
Description: ------------ number_format() seems to be having problems with large numbers. I've found two different bugs, where one can segfault Apache. They are tested on both 4.3.4 and 5.0RC1 on Linux, and 4.3.4 on Windows. Bugs happens in all of them. -- Calling the function on numbers higher than (and including) 1e71, it will display a wrong result. Some numbers will have one 0 replaced with a 7, while some will be a digit too short, but be very close to the number it is supposed to show. -- When calling number_format() on numbers bigger than (and including) 1e80, it will either return nothing or crash, depending on the 'decimals' parameter. If 'decimals' is bigger then 0, then it will return nothing. If 'decimals' is lower then 1, Apache will segfault. Reproduce code: --------------- $ php -r "echo number_format(1e71, 0, '', ' ');" 100 000 000 000 000 070 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 $ php -r "echo number_format(1e72, 0, '', ' ');" 999 999 999 999 999 600 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 $ php -r "echo number_format(1e80, 3, '', ' ');" $ php -r "echo number_format(1e80, 0, '', ' ');" Segmentation fault Expected result: ---------------- 100 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 1 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000.000 10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 Actual result: -------------- Bug 1: Wrong numbers, as shown above. Bug 2: Nothing or a segfault, as show above.
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2004-12-12 23:52 UTC] sniper@php.net
[2005-03-30 10:58 UTC] kameshj at fastmail dot fm
[2005-11-01 11:31 UTC] sniper@php.net
[2005-12-21 23:33 UTC] sniper@php.net
[2005-12-25 17:27 UTC] sniper@php.net
[2005-12-26 15:49 UTC] helly@php.net