News for hackers. Stuff that matters.
Re:Java Hangs When Converting 2.2250738585072012e-308 by pilif on Tuesday February 01, 2011 @04:31AM (#2165005)
I remember when everyone was bashing PHP (http://news.ycombinator.com/item?id=2066084) when they were bitten by the same issue. Then there were articles about this being maybe a GCC bug or at least design issue but people were still saying that it's PHP's duty to take care of this.

I was always afraid that this might bite other environments too as the code that caused the issue in PHP was apparently taken from elsewhere (see http://blog.andreas.org/display?id=9 for a detailed analysis of the problem). Now this is turning out to be true.

Re:Java Hangs When Converting 2.2250738585072012e-308 by SingAlong on Tuesday February 01, 2011 @05:10AM (#2165072)
Rasmus just tweeted about it:

Java's turn to deal with the x87 register issue. Here's a hint Oracle, "volatile"

http://twitter.com/rasmus/status/32365768603602944

Re:Java Hangs When Converting 2.2250738585072012e-308 by eonwe on Tuesday February 01, 2011 @09:32AM (#2165580)
Rasmussen's hint would work were the number parsing in Oracle's JDK implemented in in C.

Volatile keyword in Java does not guarantee writing to memory and reading it back (http://java.sun.com/docs/books/jls/third_edition/html/classe...), but using strictfp as a modifier to the method should cause the usage of strict IEEE 64-bit floating point.

Re:Java Hangs When Converting 2.2250738585072012e-308 by rll on Tuesday February 01, 2011 @12:22PM (#2166316)
Well, the underlying JVM is written in C (C++ actually) along with a bunch of assembly. I figured this needs to be fixed at the JVM level and as such the fix might very well be a single "volatile" addition like it was for PHP.
Re:Java Hangs When Converting 2.2250738585072012e-308 by eonwe on Tuesday February 01, 2011 @03:22PM (#2167176)
Yeah, the JVM is written in C++ but the problem is in Oracle's JDK written in Java. More specifically, line 1596 in FloatingDecimal.java (http://www.docjar.com/html/api/sun/misc/FloatingDecimal.java...) is the only place in the correctionLoop that can cause infinite looping. I do not purport to understand what the ulp-function does but clearly it does produce the denormal number we would want.

The interesting value here (dValue) is double but the method is without strictfp-qualifier and thus allowed to use not-quite IEEE-754 doubles.

Were the problem at JVM level, I would think that many numeric libraries written in Java would not work either and the problem would've been spotted earlier.

Edit: Thought Markdown syntax for links was in use here.

Re:Java Hangs When Converting 2.2250738585072012e-308 by rll on Tuesday February 01, 2011 @03:54PM (#2167334)
So a Java double by default allows extended precision beyond the actual double precision the type implies? I can see why it is useful for certain apps to have this capability, and it makes the problem for Java much like the problem for gcc. Most people don't know about it and can be bitten by it, as we have seen, but there are also apps that make use of this extra precision. And yes, I don't know much about Java internals.
Re:Java Hangs When Converting 2.2250738585072012e-308 by Uchikoma on Tuesday February 01, 2011 @05:52AM (#2165143)
Yes, astonishing how Oracle (and others) didn't check their code when this surfaced in PHP to determine if they are affected too.
Re:Java Hangs When Converting 2.2250738585072012e-308 by gaius on Tuesday February 01, 2011 @07:39AM (#2165307)
Yet not astonishing how the GCC team didn't fix it once, for everyone?

PS I am pretty sure Oracle, at least on Sun, used SPARCworks compiler, not GCC, from linking C++ against their libs.

Re:Java Hangs When Converting 2.2250738585072012e-308 by pilif on Tuesday February 01, 2011 @08:54AM (#2165443)
They did fix it in 4.5 by having you to pass

    -fexcess-precision=standard
Which apparently defaults to not being standard compliant.
Re:Java Hangs When Converting 2.2250738585072012e-308 by krakensden on Tuesday February 01, 2011 @03:01PM (#2167089)
it depends on how you define 'standard compliant', and fiddling with floating point behavior tends to break programs and make people angry.
Re:Java Hangs When Converting 2.2250738585072012e-308 by mjw on Tuesday February 01, 2011 @06:07AM (#2165165)
Ouch.

This affects JRuby, and potentially anyone with a JSON-based API running on the JVM with a JSON parser using the java stdlib to parse JSON floats:

    jruby-1.5.2 > JSON.parse('{"float": 2.2250738585072012e-308}')  
    ^C^C^C^C^C^C
    ^C^C^C
(not the most recent JRuby I know, but seems this is a JVM problem...)
Re:Java Hangs When Converting 2.2250738585072012e-308 by praptak on Tuesday February 01, 2011 @04:36AM (#2165018)
"Konstantin reported this problem to Oracle three weeks ago, but is still waiting for a reply."

This speaks volumes about Oracle as the Java's steward.

Re:Java Hangs When Converting 2.2250738585072012e-308 by mavroprovato on Tuesday February 01, 2011 @05:24AM (#2165095)
Sun wasn't much better in this regard
Re:Java Hangs When Converting 2.2250738585072012e-308 by nikster on Tuesday February 01, 2011 @09:06AM (#2165490)
I just reported a problem last week and got a response inside 12 hours. I was amazed. Certainly faster than I've ever gotten a response from Sun.

Average over the last 3 issues is about 48 hours - if accepted as a bug. But if you provide source code that demonstrates the problem turnaround is usually very fast, and that seems to be the case here.

Re:Java Hangs When Converting 2.2250738585072012e-308 by andrew1 on Tuesday February 01, 2011 @05:46AM (#2165131)
So they're not falling over themselves to fix a bug which no one has noticed for 10+ years, and which hardly anyone is going to hit in actual use. Maybe they're spending their time fixing problems which are actually affecting developers.
Re:Java Hangs When Converting 2.2250738585072012e-308 by mhansen on Tuesday February 01, 2011 @05:49AM (#2165137)
Any public-facing Java server affected by this bug that accepts floating point numbers from the user as a string can be hung by this bug.

This is going to be a big problem.

Re:Java Hangs When Converting 2.2250738585072012e-308 by stevie_wilks on Tuesday February 01, 2011 @07:41AM (#2165310)
Excellent point. I'm going to have some tests to run when I get in to work this morning.
Re:Java Hangs When Converting 2.2250738585072012e-308 by ashutoshmehra on Wednesday February 02, 2011 @09:20AM (#2170286)
Yup. A comment on the original webpage reported that this value appears to hang/time-out Google Spreadsheet. I tested and it indeed was the case. So there are going to be lots of places one can fool around on the input side only to send the server thread into a loop. That's bad.
Re:Java Hangs When Converting 2.2250738585072012e-308 by sigzero on Tuesday February 01, 2011 @09:55AM (#2165670)
And yet...in 10+ years...it hasn't been a problem? Certainly the need to fix it but saying it is going to be a "big problem" is a bit theatrical.
Re:Java Hangs When Converting 2.2250738585072012e-308 by steveklabnik on Tuesday February 01, 2011 @11:20AM (#2166019)
Well, yeah. Nobody _accidentally_ hit upon this number, but now that it's a known way to commit a denial of service attack, people are going to take advantage of it.

Imagine your response, but about a kernel privilege escalation bug:

"And yet...in 10+ years...it hasn't been a problem? Certainly the need to fix it but saying it is going to be a "big problem" is a bit theatrical."

Re:Java Hangs When Converting 2.2250738585072012e-308 by VMG on Tuesday February 01, 2011 @08:56AM (#2165452)
I tried to dig up a list of websites with a java-backend but my google-fu is not strong enough. I don't think that there are actually many big sites running on java.
Re:Java Hangs When Converting 2.2250738585072012e-308 by al05 on Tuesday February 01, 2011 @09:19AM (#2165518)
There are tons of sites running on java. Possibly more than php.
Re:Java Hangs When Converting 2.2250738585072012e-308 by quomopete on Tuesday February 01, 2011 @10:56AM (#2165909)
Yup - http://wiki.java.net/bin/view/Projects/RealWorldJSFLinks

Anecdotally, a lot of those [\w+]tube porn sites probably run on a Java server considering the heavy lifting that goes on there.

Re:Java Hangs When Converting 2.2250738585072012e-308 by exec on Tuesday February 01, 2011 @12:46PM (#2166403)
Most of internet banking systems in my country run on Java. And most of them can be affected if you know where to put this number.
Re:Java Hangs When Converting 2.2250738585072012e-308 by Sandman on Tuesday February 01, 2011 @01:42PM (#2166663)
Yes, but fortunately, there is not much reason why anybody would use double when developing a banking system.
Re:Java Hangs When Converting 2.2250738585072012e-308 by yyyy on Wednesday February 02, 2011 @02:35PM (#2171710)
They don't have to use it directly.

GET / HTTP/1.0

Accept-Language: en;q=2.2250738585072012e-308

If you're running Tomcat and you call getLocale() on that servlet request, you're toast.

Re:Java Hangs When Converting 2.2250738585072012e-308 by wingo on Tuesday February 08, 2011 @09:26AM (#2192917)
This is precisely why "q" is defined only to accept three digits after the decimal. It's actually not a floating point number, and anyone who parses it as such is just being lazy.

"q" is more properly represented natively as an integer between 0 and 1000.

Re:Java Hangs When Converting 2.2250738585072012e-308 by xcombelle on Wednesday February 16, 2011 @10:38AM (#2226747)
apparently q is not properly parsed in JBoss which is based on apache tomcat scaring not?
Re:Java Hangs When Converting 2.2250738585072012e-308 by rll on Tuesday February 01, 2011 @04:15AM (#2164967)
I have a feeling we will see this come up in more places. When we fixed the code for PHP we saw very similar code in a lot of other projects.
Re:Java Hangs When Converting 2.2250738585072012e-308 by wladimir on Tuesday February 01, 2011 @06:00AM (#2165154)
Yes, every project should check its strtod function. If it has a potentially infinite loop, be very worried :)
Re:Java Hangs When Converting 2.2250738585072012e-308 by snewman on Tuesday February 01, 2011 @10:50AM (#2165885)
If I'm not mistaken, this is bad: it enables a trivial DOS attack against any web service that accepts floating-point input. (For instance, one of the commenters on the OP noted that Google Spreadsheets backends are vulnerable.) This includes, as a special case, any service that accepts JSON input.

I expect a lot of teams will have to rush out a patch. I feel for them...

Incidentally, I haven't seen a simple workaround posted anywhere. Has anyone seen a regexp or code snippet that can identify strings which would trigger this bug?

Re:Java Hangs When Converting 2.2250738585072012e-308 by djacobs on Tuesday February 01, 2011 @10:52AM (#2165896)
Maybe I'm dense, but why does this affect apps that use JSON?
Re:Java Hangs When Converting 2.2250738585072012e-308 by snewman on Tuesday February 01, 2011 @11:41AM (#2166111)
Because JSON can include floating-point numbers. If you pass { foo: 2.2250738585072012e-308 } to any JSON service, I'd expect it to invoke Double.parseDouble(...) as part of its input processing, and trip over the bug. This would probably occur before any type checking of the input, and thus would probably work even for a service which does not expect floating-point inputs.
Re:Java Hangs When Converting 2.2250738585072012e-308 by woogley on Tuesday February 01, 2011 @01:45PM (#2166683)
This is not correct. Think about a service which used PHP's json_decode function. PHP has fixed this bug, so there would be no issue.

The problem has nothing to do with JSON. It only affects JSON parsers that run on a JVM.

Re:Java Hangs When Converting 2.2250738585072012e-308 by snewman on Tuesday February 01, 2011 @04:23PM (#2167471)
Right -- when I said "any service that accepts JSON input", I meant "any JVM-based service that accepts JSON input". I thought the JVM qualification would be clear from the context of this thread, apologies if it wasn't.
Re:Java Hangs When Converting 2.2250738585072012e-308 by djacobs on Tuesday February 01, 2011 @12:19PM (#2166307)
So the exact same bug affects Javascript?
Re:Java Hangs When Converting 2.2250738585072012e-308 by eru on Tuesday February 01, 2011 @01:32PM (#2166621)
JSON just makes it quite easy to parse in a floating point number. But that doesn't have anything to do with Javascript per-se.
Re:Java Hangs When Converting 2.2250738585072012e-308 by abscondment on Tuesday February 01, 2011 @04:07AM (#2164954)
The compile-time version will hang a Clojure REPL, too:

user=> (def d 2.2250738585072012e-308)

Re:Java Hangs When Converting 2.2250738585072012e-308 by paulitex on Tuesday February 01, 2011 @04:14AM (#2164965)
makes sense, same thing in scala:

Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22). Type in expressions to have them evaluated. Type :help for more information.

scala> 2.2250738585072012e-308

(infinite loop)

Re:Java Hangs When Converting 2.2250738585072012e-308 by Jach on Tuesday February 01, 2011 @04:13AM (#2164963)
Tried it in Jython too, of course it fails. I'd have been more surprised if it worked, but it's still amusing and had to see it.
Re:Java Hangs When Converting 2.2250738585072012e-308 by latch on Tuesday February 01, 2011 @03:51AM (#2164919)
The compiler one is pretty neat. Hung IntelliJ. Didn't hang VS.NET. Had both open, had to try.
Re:Java Hangs When Converting 2.2250738585072012e-308 by leppie on Tuesday February 01, 2011 @04:18AM (#2164972)
Just to confirm .NET/C# handles this and correctly. So does IronScheme.
Re:Java Hangs When Converting 2.2250738585072012e-308 by Torn on Tuesday February 01, 2011 @06:16AM (#2165185)
Why would a Java / JVM issue hang the .NET CLR?
Re:Java Hangs When Converting 2.2250738585072012e-308 by dagw on Tuesday February 01, 2011 @06:23AM (#2165196)
Because by all accounts this isn't a Java/JVM issue. It's a flaw in a commonly used algorithm for handling floating point numbers. Given that php and possibly gcc use variations on the same algorithm, and have the same flaw, it's not unreasonable to think that other languages/compilers/runtimes would also be affected.
Re:Java Hangs When Converting 2.2250738585072012e-308 by Torn on Tuesday February 01, 2011 @06:30AM (#2165211)
Thanks for the clarification.
Re:Java Hangs When Converting 2.2250738585072012e-308 by giu on Tuesday February 01, 2011 @06:27AM (#2165206)
As the article "The PHP strtod() denial of service bug" (http://blog.andreas.org/display?id=9 ; linked by pilif in another comment) states, it looks like the code for the conversion is used in a few prominent libraries (e.g. Apple's libc, Android libc, GCC libio etc.). Therefore, it could've been quite possible that the mentioned code has been adopted by Microsoft, too; leppie just confirmed that everything works fine over there.
Re:Java Hangs When Converting 2.2250738585072012e-308 by leppie on Tuesday February 01, 2011 @06:42AM (#2165231)
You obviously did not read the Moonlight vs IcedTea issue in Chrome article yesterday ;)
Re:Java Hangs When Converting 2.2250738585072012e-308 by DrJokepu on Tuesday February 01, 2011 @06:25AM (#2165201)
I guess because only a couple of weeks ago a similar issue has surfaced in PHP so it is not entirely unreasonable to check whether other runtimes have similar problems?
Re:Java Hangs When Converting 2.2250738585072012e-308 by Stasyan on Tuesday February 01, 2011 @10:06AM (#2165704)
F# is fine as well
Re:Java Hangs When Converting 2.2250738585072012e-308 by lukesandberg on Tuesday February 01, 2011 @08:16AM (#2165371)
This hangs eclipse 3.5.2 when saving the code :)
Re:Java Hangs When Converting 2.2250738585072012e-308 by sjs on Tuesday February 01, 2011 @12:59PM (#2166463)
Ugh, not only that but it hosed my workspace :/

Don't try this in a project you're currently working on. Now I have to spend my morning trying to unfuck my project.

Re:Java Hangs When Converting 2.2250738585072012e-308 by ibejoeb on Tuesday February 01, 2011 @07:25AM (#2165287)
FWIW the Oracle/BEA jrockit compiler does not hang. It does hang on execution, however.

   Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
   Oracle JRockit(R) (build R28.0.1-21-133393-1.6.0_20-20100512-2126-linux-ia32, compiled mode)
Re:Java Hangs When Converting 2.2250738585072012e-308 by VMG on Tuesday February 01, 2011 @07:50AM (#2165322)
Re:Java Hangs When Converting 2.2250738585072012e-308 by Uchikoma on Tuesday February 01, 2011 @05:51AM (#2165139)
I assume this hits Clojure, JRuby, etc. harder because it affects all values which are converted to Strings, but only affects Java when one explicitly converts to Double?

So when a (Java) website expects an Int as input, it's not affected, but Clojure,JRuby etc would be?

Am I right, what am I missing?

(see the comment with

user=> (def d 2.2250738585072012e-308)

)

Re:Java Hangs When Converting 2.2250738585072012e-308 by r0h4n on Tuesday February 01, 2011 @05:05AM (#2165063)
Doesnt hang Ruby 1.9 (MRI) and python 2.7 and python 3.1
Re:Java Hangs When Converting 2.2250738585072012e-308 by speleding on Tuesday February 01, 2011 @05:23AM (#2165091)
Ruby 1.8.7 appears to be fine too
Re:Java Hangs When Converting 2.2250738585072012e-308 by rll on Tuesday February 01, 2011 @05:45AM (#2165125)
This particular value is specific to the Java implementation. Ruby has very similar code to PHP though, so a slight variation of the value may trigger it. You also have to be on a platform that actually has an x87, of course.
Re:Java Hangs When Converting 2.2250738585072012e-308 by cygwin98 on Tuesday February 01, 2011 @09:10AM (#2165501)
Ruby 1.9.2 handled it well here
Re:Java Hangs When Converting 2.2250738585072012e-308 by joeyh on Tuesday February 01, 2011 @01:57PM (#2166740)
So, in summary, we've made counting on computers so complex that we're still failing to get it right. Similarly to how we've made the alphabet (unicode) on computers so complex that most programs are still trying to get that right.
Re:Java Hangs When Converting 2.2250738585072012e-308 by russell on Tuesday February 01, 2011 @02:38PM (#2166956)
This seems to be a not rare occurrence around the phase boundaries of functions. I had a similar problem with the atan2 function in the PL/I - Fortran library on the CDC 6600. One of my testers was stepping across the boundary between valid and invalid arguments and there was a single binary value that blew up. I was the compiler lead so it got fixed. Any of you remember the 486 floating point problem?
Re:Java Hangs When Converting 2.2250738585072012e-308 by VMG on Tuesday February 01, 2011 @08:18AM (#2165377)
What about android?
Re:Java Hangs When Converting 2.2250738585072012e-308 by dfox on Tuesday February 01, 2011 @10:59AM (#2165920)
Android is not i386 based and this is x87 FPU and gcc specific bug in commonly used atod() implementation, so I assume that this does not happen on Android.
Re:Java Hangs When Converting 2.2250738585072012e-308 by VMG on Tuesday February 01, 2011 @02:41PM (#2166980)
The bug is in the JDK code running on a JVM (I posted a link to the source). Also runhang.java hangs on my 64bit java vm.
Re:Java Hangs When Converting 2.2250738585072012e-308 by tytso on Wednesday February 02, 2011 @05:19PM (#2172454)
Obvious question --- are there any java web services running at Oracle that take a string input from a form or a URL, and tries to convert said stirng to a floating point variable?
Re:Java Hangs When Converting 2.2250738585072012e-308 by jd0g on Friday February 04, 2011 @11:59AM (#2180096)
I cannot recreate this using Spring TC (http://www.springsource.com/products/tcserver) server.
Re:Java Hangs When Converting 2.2250738585072012e-308 by wildmXranat on Tuesday February 01, 2011 @08:46AM (#2165424)
In that case, this still applies: http://zenebo.com/cmc/1/