Skip to content

fix(gossipsub): check frame length against max_transmit_size - #6645

Open
kriss39 wants to merge 5 commits into
libp2p:masterfrom
kriss39:fix/gossipsub-frame-length
Open

kriss39 wants to merge 5 commits into
libp2p:masterfrom
kriss39:fix/gossipsub-frame-length

Conversation

@kriss39

@kriss39 kriss39 commented Sep 30, 2026

Copy link
Copy Markdown

Description

validate_rpc_limits (added in #6491) compares buf.len() with max_transmit_size. The decoder gets everything FramedRead has read so far, and FramedRead reads in 8 KiB chunks, so the buffer can already contain the beginning of the next frame. If a frame close to the limit is followed by another one, the check fails even though both are within the limit. The inbound stream then goes to Closing, the buffered frames are lost, and after a few of these the handler disables the protocol for the connection.

This reads the varint length prefix of the current frame and checks that against the limit. An oversized frame is still rejected as soon as its prefix arrives, so the goal of #6491 is kept.

Two tests are added: three RPCs of 60 000 / 64 000 / 60 000 bytes decoded through FramedRead with the default 64 KiB limit (fails on master with message with 71054b exceeds maximum of 65536b), and a partially received oversized frame that must still be rejected.

Notes & open questions

A frame whose payload is exactly max_transmit_size was also rejected before because the length prefix was counted; it is accepted now.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

`validate_rpc_limits` compared `src.len()` with `max_transmit_size`, but
`FramedRead` hands the decoder everything it has read so far, which can
already include the start of the next frame. Two RPCs that are both under
the limit could therefore be rejected, which closes the inbound stream.

Read the varint length prefix and compare that instead, so an oversized
frame is still rejected before it is fully buffered.
@mergify

mergify Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts. Could you please resolve them @kriss39? 🙏

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.

1 participant