Skip to content

Support ext formats in MessageLen and report limit violations as ParseError - #388

Open
baszalmstra wants to merge 4 commits into
3Hren:masterfrom
baszalmstra:est-ext-limits
Open

Support ext formats in MessageLen and report limit violations as ParseError#388
baszalmstra wants to merge 4 commits into
3Hren:masterfrom
baszalmstra:est-ext-limits

Conversation

@baszalmstra

@baszalmstra baszalmstra commented Aug 31, 2026

Copy link
Copy Markdown

Builds on #374 by @eggyal (cherry-picked as the first commit, please keep the credit) and adds a few things I ran into while trying to use MessageLen to find the end of a value:

  • Limit violations were reported as Truncated(n) on the call that hit them; ParseError only showed up on the next call. So len_of on a complete over-limit message said "needs more data". It is now ParseError right away, and sticky until reset().
  • The reserved marker 0xc1 counted as a one-byte value. Every decoder in this repo rejects it, so MessageLen now does too. This is a behaviour change, happy to drop it if you'd rather keep this lenient.
  • While the length prefix of an ext8/16/32 is being read the type byte is already known to follow, so the lower bound now includes it.
  • More ext tests: ext32, the u8/u16 boundary lengths, and ext values nested in arrays/maps so resumption inside a sequence is covered.

Each follow-up commit adds its tests first, so it should be easy to review them one by one. cargo test --workspace passes.

eggyal and others added 4 commits August 31, 2026 10:41
Extends the ext coverage from the previous commit with the ext32 format
(both a small non-canonical length checked for every prefix, and a
canonical 70k payload), the u8/u16 boundary lengths, and ext values
inside arrays and maps so that resumption of an interrupted ext inside
a sequence is exercised too.

Claude-Session: https://claude.ai/code/session_011NAQi5b2wGJsRjiEcCHjZ8
Exceeding the depth or length limit set the LimitExceeded state, but the
call that hit it still reported `Truncated(lower_bound)`; only the next
call returned `ParseError`. A caller using `len_of` on a complete
message therefore saw "needs more data" for an over-limit message, and
a streaming caller had to make one extra round trip to learn the
message was unparseable.

`incremental_len` now reports `ParseError` as soon as a sticky state is
entered. A second sticky state, `Reserved`, is added for the reserved
marker 0xc1, which every decoder in this repository rejects but
MessageLen used to count as a one-byte value.

Claude-Session: https://claude.ai/code/session_011NAQi5b2wGJsRjiEcCHjZ8
While the length prefix of an ext8/16/32 value is still being read, the
type byte is already known to follow it, so include it in the estimate.
Also documents that `max_len` applies to ext payloads and why `len + 1`
cannot overflow.

Claude-Session: https://claude.ai/code/session_011NAQi5b2wGJsRjiEcCHjZ8
@baszalmstra
baszalmstra marked this pull request as ready for review August 31, 2026 10:06
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