-
Notifications
You must be signed in to change notification settings - Fork 365
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
UltraJSON has inconsistent behavior on parsing large integral values. #440
Comments
This is happening due to incorrect overflow* detection. The decoder parses the input digit by digit. Every time, the previous value is multiplied by ten and the next digit added. After that, there is an attempt to check whether the result is smaller than the previous value. However, overflows can happen without triggering that check. For example, let's take the input (* Technically, unsigned ints cannot actually overflow (cause undefined behaviour etc.) in C. I'm using 'overflow' in the looser sense to mean wrapping around.) |
Should |
I don't think that matching constraints caused by JavaScript's slightly questionable behaviour of munging integers and floats under the hood would make us very popular - especially given that Python's |
Ok, works for me ;) |
never the less https://datatracker.ietf.org/doc/html/rfc7159#section-6 recommends considering the range |
ujson is compatible with that as it already supports the range |
I believe that @jlusiardi is suggesting that we change ujson to raise an error for any value outside of the range |
Hmm, right. I'm not a fan of artificially restricting the range like that. But now I wonder why we aren't just reading digits into a |
I agree. If JSON was used exclusively by JavaScript talking to other JavaScript applications then I would enforce the limited range but since JSON has become pretty universal, I don't think it makes sense to inherit JavaScript's shortcomings.
I think it's just for the perceived cleanliness of having a pure C implementation in a |
Good point, and I do like that, actually. We could add an extra type for these, e.g. |
|
Well, not quite an alias, just an entry in the |
For some integers that are too large, UltraJSON will raise a ValueError. For others, it will parse, but parse to the wrong value. This happens both for numbers that are too large in the positive direction, and numbers that are too large in the negative direction.
What did you do?
Encoded an integer that was too big or too small.
What did you expect to happen?
I expected UltraJSON to raise a ValueError.
What actually happened?
UltraJSON parsed the integer...into the wrong value.
What versions are you using?
Please include code that reproduces the issue.
The text was updated successfully, but these errors were encountered: