Skip to content

fix: reject overlong FAST varints that silently truncate - #27

Merged
ruoka merged 2 commits into
masterfrom
cursor/critical-bug-management-ce3c
Jul 27, 2026
Merged

fix: reject overlong FAST varints that silently truncate#27
ruoka merged 2 commits into
masterfrom
cursor/critical-bug-management-ce3c

Conversation

@cursor

@cursor cursor Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

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 as 0 instead of failing.

Impact: silent corruption of FSON integers, doubles (via bit_cast of uint64), and timestamps — all share these decoders on the storage path.

Root cause

Decode looped i = (i << 7) | (byte & 0x7f) with no ceil(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

  • Added FAST unit tests for overlong 32/64-bit cases and an FSON root-integer regression.
  • ./tools/CB.sh debug test --tags='\[xson\]' — 425/425 passed.
Open in Web View Automation 

cursoragent and others added 2 commits July 27, 2026 15:32
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
ruoka marked this pull request as ready for review July 27, 2026 18:42
@ruoka
ruoka merged commit eb810f7 into master Jul 27, 2026
4 checks passed
@ruoka
ruoka deleted the cursor/critical-bug-management-ce3c branch July 27, 2026 18:42
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>
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