PHP Floating Point Bug Crashes Servers
angry tapir writes "A newly unearthed bug in certain versions of the PHP scripting language could crash servers when the software is given the task of converting a large floating point number, raising the possibility that the glitch could be exploited by hackers. The bug will cause the PHP processing software to enter an infinite loop when it tries to convert the series of digits "2.2250738585072011e-308" from the string format into the floating point format. The bug only seems to affect version 5.2 and 5.3 of the language." Adds reader alphadogg: "Computer scientist Rick Regan first reported the bug on Monday, and the PHP development team issued patches the following day."
The 1 day turn around for a patch is pretty impressive. I wish some bigger companies would offer such fast patches against vulnerabilities..
Step 1: Write stuff in PHP
Step 2: ???
Step 2.9999990834239320: Profit!
Maybe I'm missing something, but why does PHP have its own version of strtod()? It's a standard C99 function, so you'll find it in libc or equivalent in any C99-compliant platform (including Windows) and more effort has probably gone into optimising that version than the PHP version, although if you're converting from strings to floating point values anywhere performance critical then you're probably Doing It Wrong.
Did the Zend team think that there weren't enough security holes in PHP and decide to increase the attack surface?
I am TheRaven on Soylent News
Please - don't you remember the last time we did that?
Oh, I guess you wouldn't.
Sweet. PHP finally has the qualifications to enter the X86 CPU market.
That is a regular expression. It searches for the word imgladiusedperl .
I mean, for all practical purposes, it's an infinitely small number, so why shouldn't it be an infinite loop?
make imaginary.friends COUNT=100 VISIBLE=false
Am I the only one to notice that 2.2250738585072011e-308 is not very large?
Apparently, some journalists need a patch too.
My 2.2250738585072011e-308 cents.
It's one digit (the last one before the e; should be a 4 instead of a 1) from the minimum positive value for an IEEE-754 double precision floating-point number.
GLaDOS for President 2016! "Well here we are again. It's always such a pleasure." -- GLaDOS, 2011
The inconsistent type system, lack of Unicode support, lack of namespaces, quirky parser, and other stupidities (== vs. ===) weren't enough, so. Is this bug inane enough to actually get people to realize that PHP bites?
~ C.
Comment removed based on user account deletion
The x87 registers are all 80 bits long, while standard doubles are only 64 bits. You can get into a situation where two floating point registers contain different values that round to the same double value, yet they don't compare equal. Adding the volatile keyword forces the compiler to copy the registers to the stack and read them back every time they are accessed, truncating them to 64 bits. The patch is only needed on x86 because x86_64 uses SSE3 for floating point, which works with 64-bit floats natively.
(2) A partial but simple solution: Do comparisons on volatile variables only.
Hope this has been enlightening!