Skip to content

Reject a frame announcing more bytes than follow it - #28

Open
bavulapati wants to merge 1 commit into
mainfrom
reject-frame-past-the-end
Open

bavulapati wants to merge 1 commit into
mainfrom
reject-frame-past-the-end

Conversation

@bavulapati

Copy link
Copy Markdown
Contributor

_Frame.decode took the announced length on trust: it set state.end to where the frame claimed to end without checking that against where the buffer actually ends. So 0501, five bytes announced with one behind it, decoded as 1 and left state.start at 6 in a 2-byte buffer.

The wrong answer is the smaller half. state.remaining goes negative, so every later read works from a position that does not exist, and a truncated or hostile frame corrupts what follows it rather than failing where the problem is.

One comparison fixes it, before state.end moves. Reading the value inside the announced length and rejecting what runs past it is a separate rule, frame-bounds-its-value, which this port already passed and test_frame_decode_restores_end_on_inner_error already covers.

Conformance against compact-encoding-test goes from 171 matched / 3 diverged to 172 / 2, closing frame-uint-length-past-the-end. The two left are #19.

Closes #18.

Decode trusted the announced length, so a short frame read its value and left
the cursor past the end of the buffer, where state.remaining goes negative and
everything decoded after it works from a position that does not exist.

Closes #18.
@bavulapati
bavulapati requested a review from a team November 20, 2026 15:02

This branch has not been deployed

No deployments
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.

frame decodes past the end of the input and leaves the state there

1 participant