Skip to content

Reject a decimal integer that overflows Int64 - #135

Merged
xoofx merged 1 commit into
xoofx:mainfrom
dngr2:reject-int64-overflow
Aug 18, 2026
Merged

Reject a decimal integer that overflows Int64#135
xoofx merged 1 commit into
xoofx:mainfrom
dngr2:reject-int64-overflow

Conversation

@dngr2

@dngr2 dngr2 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

TryParseDecimalInt64 accumulates digits into a ulong and guards only against exceeding ulong.MaxValue. The negative branch then rejects magnitudes above 2^63, but the positive fall-through has no matching upper bound, so a decimal literal in [2^63, 2^64-1] is accepted and the ulonglong cast wraps it negative:

a = 9223372036854775808   ->  parsed as -9223372036854775808
a = 18446744073709551615  ->  parsed as -1

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.MaxValue guard. Int64.MaxValue/Int64.MinValue still parse; added a test. (Hex 0xFFFFFFFFFFFFFFFF is likewise accepted as -1, but I kept this to the unambiguous decimal case.)

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.
@xoofx
xoofx merged commit 353e75d into xoofx:main Aug 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants