-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
JSON parsing of large 32-bit floating point values fails. #10509
Comments
@mcy: This feels like something that could usefully be in the JSON conformance test suite. (I'm adding unit tests to the C# code of course.) |
The conformance tests already have a "max float" case, but they are testing for protobuf/conformance/binary_json_conformance_suite.cc Lines 2085 to 2088 in f8be281
Also it appears the min float case has a copy-and-paste bug, where it's accidentally checking the max float value again: protobuf/conformance/binary_json_conformance_suite.cc Lines 2089 to 2092 in f8be281
|
The proto3 JSON spec doesn't give very much guidance on exactly how floating point values are represented.
The maximal finite 32-bit floating point value is precisely 340282346638528859811704183484516925440. Both .NET and (I believe) Go format this as 3.4028235e+38.
Unfortunately that fails to round-trip in .NET, because of the way we handle JSON parsing of 32-bit floating point numbers:
There are 64-bit floating point values closer to 3.4028235e+38 than the max 32-bit value, so we end up throwing an exception.
We should, instead, try casting to
float
and see whether the result is infinite.The text was updated successfully, but these errors were encountered: