Repository navigation
Fix xid8 overflow when decoding values for sql.Scanner - #2693
Merged
Merged
Conversation
Uint64Codec.DecodeDatabaseSQLValue cast uint64 values to int64 without checking the range. Values above math.MaxInt64 were therefore passed to sql.Scanner as negative integers. Reuse Uint64.Value so values within the signed range remain int64 and larger values are represented as decimal strings without losing data. Add regression coverage for the signed boundary, maximum uint64, and NULL in both text and binary formats.
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.
Uint64Codec.DecodeDatabaseSQLValueunconditionally casts decoded values toint64. When anxid8value exceedsmath.MaxInt64, scanners receive a negative integer without an error. For example,18446744073709551615is read as"-1"throughsql.NullString.Reuse
Uint64.Value()to preserve the full unsigned range. Values within the signed range remainint64, larger values are returned as decimal strings, and NULL remains nil. This also allows scanners targetingint64to report an out-of-range error instead of accepting a wrapped value.Add regression coverage for
math.MaxInt64,math.MaxInt64 + 1,math.MaxUint64, and NULL in both text and binary formats. The regression test fails before the fix and passes afterward.Validation:
Passed with Go 1.25.5 against a temporary PostgreSQL 20devel instance.
Closes #2692