Repository navigation
Conversation
MySQL sends DECIMAL/NEWDECIMAL as ASCII text even over the binary protocol, but int_decode/uint_decode read those bytes as a little-endian integer. Decoding e.g. SUM(int_col) into u64 via a type override or try_get_unchecked silently produced garbage (b"13" read as 0x3331 = 13105 instead of 13). Parse the text for DECIMAL columns and require it to be integral: integral values decode correctly, while fractional ones now return an error instead of a corrupted result. Type::compatible is left unchanged, so query! inference still maps DECIMAL columns to Decimal/BigDecimal.
Map130
marked this pull request as ready for review
November 3, 2026 15:30
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.
This reworks #4422, which you suggested I reopen as a separate PR. Same fix,
with the issues from last time sorted out.
When decoding a MySQL DECIMAL/NEWDECIMAL column into an integer type, you get
the wrong value. MySQL sends these columns as ASCII text even over the binary
protocol (a SUM() over integers is one way to hit this), but int_decode and
uint_decode read the bytes as a little-endian integer.
So a DECIMAL(4,0) of 13 comes over the wire as the bytes 0x31 0x33 ("13"), and
reading that as little-endian gives 0x3331 = 13105. It's silent: nothing errors,
you just get a garbage number. I ran into it in production reading an aggregate
into u64 via try_get_unchecked. The checked query_scalar! path infers Decimal
and isn't affected, which is why it slipped through.
The fix special-cases DECIMAL/NEWDECIMAL in int_decode/uint_decode: parse the
text and require it to be integral. Integral values decode correctly; a value
with an actual fractional part returns an error instead of a corrupted result.
Negative values only decode into signed types. Type::compatible is left alone,
so the macros still map DECIMAL to Decimal/BigDecimal as before.
Is this a breaking change?
Yes, but a mild one. Decoding a DECIMAL into an integer used to give a corrupted
value (or a ParseIntError over the text protocol); now it gives the correct
value, or a clean error on a fractional part. Someone could in theory have
depended on the old output, but it was data corruption. The checked macros are
unaffected since Type::compatible is unchanged.