fix: reject overlong FAST varints that silently truncate - #27
Merged
Conversation
Varint decode shifted every continuation byte into a fixed-width register with no length cap, so an 11-byte uint64/int64 (or 6-byte 32-bit) ending in the stop bit succeeded with high payload bits shifted away (e.g. [0x01, nine 0x00, 0x80] → 0). Cap at ceil(bits/7) and reject past that; FSON integers/doubles/timestamps share these decoders. Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
ruoka
marked this pull request as ready for review
July 27, 2026 18:42
2 tasks
ruoka
added a commit
that referenced
this pull request
Jul 28, 2026
…#28) Byte-count caps from #27 still allowed N×7 payload bits into narrower registers, so forms like uint64 [0x02, eight 0x00, 0x80] decoded as 0. Reject shifts that would drop high bits. Also fix signed size() literals that were positive (0x00000000ffffffc0ll etc.), so small negatives encoded as 5+ bytes instead of the canonical 1–4 byte forms. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Kaius Ruokonen <ruoka@users.noreply.github.com>
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.
Bug and impact
FAST varint decode (
xson/xson-fast.c++m) accepted arbitrarily long continuation sequences as long as a stop bit eventually appeared. Extra bytes were shifted into a fixed-width register, so high payload bits were silently dropped.Trigger: an 11-byte uint64/int64 wire form such as
[0x01, nine 0x00, 0x80](or a 6-byte 32-bit form) decoded as0instead of failing.Impact: silent corruption of FSON integers, doubles (via
bit_castof uint64), and timestamps — all share these decoders on the storage path.Root cause
Decode looped
i = (i << 7) | (byte & 0x7f)with noceil(bits/7)cap (10 for 64-bit, 5 for 32-bit).Fix
Reject varints longer than the type width; throw
xson::fast overlong … varint.Validation
./tools/CB.sh debug test --tags='\[xson\]'— 425/425 passed.