Reject a decimal integer that overflows Int64 - #135
Merged
Conversation
TryParseDecimalInt64 guarded the negative branch against magnitudes above 2^63 but the positive branch had no upper bound, so a literal in [2^63, 2^64-1] wrapped to a negative long (9223372036854775808 parsed as -9223372036854775808). TOML requires an error when an integer cannot be represented losslessly. Add the symmetric guard.
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.
TryParseDecimalInt64accumulates digits into aulongand guards only against exceedingulong.MaxValue. The negative branch then rejects magnitudes above2^63, but the positive fall-through has no matching upper bound, so a decimal literal in[2^63, 2^64-1]is accepted and theulong→longcast wraps it negative:TOML v1.0.0 requires 64-bit signed integers and an error when a value can't be represented losslessly, so those must be rejected. This adds the symmetric
accumulator > long.MaxValueguard.Int64.MaxValue/Int64.MinValuestill parse; added a test. (Hex0xFFFFFFFFFFFFFFFFis likewise accepted as-1, but I kept this to the unambiguous decimal case.)