Repository navigation
Conversation
InRange() rejected a double just over a 64-bit limit by casting it to the integer type and comparing with min. That cast is undefined, and its result differs by compiler and architecture. With clang on x86-64, Value(18446744073709551616.0).asUInt64() gave 2^63 instead of throwing, which is open-source-parsers#1545 again. The same check also caught every value between 0 and 1, since those truncate to the unsigned min. Value(0.5).asUInt() threw and Value(0.5).isConvertibleTo(uintValue) was false, while 1.5 converts to 1. Compare against the limit instead: strictly when it isn't exactly representable as a double, as isInt64() and isUInt64() already do.
[Medium impact] The PR appears safe to merge.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#1519 made
InRange()reject a double just over a 64-bit limit by casting it to the integer type and comparing with min. That cast is undefined, and the result depends on the compiler: with clang on x86-64,Value(18446744073709551616.0).asUInt64()returns 2^63 instead of throwing, so #1545 is still there. gcc happens to produce 0, which the check catches.The same check also catches every value between 0 and 1, since those truncate to the unsigned min.
Value(0.5).asUInt()throws andValue(0.5).isConvertibleTo(uintValue)is false, while 1.5 converts to 1.This compares against the limit instead: strictly when it isn't exactly representable as a double, as
isInt64()andisUInt64()already do.