Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I was using JSON as an example because it's taking something in JSON specified as a string, using quotation marks, and automatically converting it to a double.

I wasn't referring to this being the cause, just in other languages if you pass a string through JSON it would never end up being decoded to a double, just because syntactically it is a double.



> taking something in JSON specified as a string, using quotation marks, and automatically converting it to a double.

I can't see anything wrong with this behavior. Double isn't supposed to be any less safe than any other type.

> I wasn't referring to this being the cause, just in other languages if you pass a string through JSON it would never end up being decoded to a double, just because syntactically it is a double.

I believe there is a fundamental misunderstanding here. Other languages would indeed convert to double if so instructed, or if the value presented was a (high) floating point value. And once again, I can see no inherent problem with a JSON parser that looks at a floating point number and interprets it as a double. The only problem would be the memory space of a double vs that of a float or smaller type, but since PHP doesn't make that distinction the point is moot. I don't see the evilness of it, nor do I see how static typing would avoid bugs such as this.

More generally speaking, if one of the basic types of a language is defectively handled, there is no way this bug goes away if you declare that type beforehand. It has quite simply nothing to do with it. I guess an argument could be made that less code would be vulnerable on account of having less instances of doubles around, but it would still be a huge problem. And it's not like floating point numbers are somehow rarely used.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: