Repository navigation
feat: add max_buffered_frame_len to limit buffered non-DATA frames - #387
Open
jeremyjpj0916 wants to merge 1 commit into
Open
jeremyjpj0916 wants to merge 1 commit into
jeremyjpj0916 wants to merge 1 commit into
Conversation
Non-DATA frames are buffered completely before they are decoded, and unknown frame types are buffered completely before they are skipped. The declared payload length was never checked, so a peer could declare a frame of up to 2^62-1 bytes and keep sending payload. QUIC flow control does not limit this, since reading from the stream grants the peer more credit. Add `max_buffered_frame_len` to the server and client builders. A non-DATA frame declaring a longer payload is refused as soon as its length is read, before the payload is buffered, with a connection error of type H3_EXCESSIVE_LOAD. The limit applies to request streams, control and push streams, and WebTransport bidirectional streams. DATA frames are streamed and are not affected. The declared length is compared as a u64 before converting it to usize, and a length that does not fit in a usize is refused for every frame type, so it cannot be truncated on 32-bit targets. The default is no limit, so existing behavior is unchanged.
This branch has not been deployed
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.
Non-
DATAframes are buffered in full before they're decoded, and unknown frame types are buffered in full before they're skipped. Nothing checks the declared payload length. When a frame hasn't fully arrived,Frame::decodereturnsIncomplete(2 + len),FrameDecoderstores it asexpected, andFrameStream::poll_nextkeeps reading into itsBufListuntil that many bytes are available.So a peer can open a request stream, send a HEADERS frame header declaring a
2^62 - 1byte payload, and keep sending bytes.accept()/resolve_request()never return, and memory grows until the process is killed. QUIC flow control doesn't stop this, because each read grants the peer more credit. The idle timeout doesn't stop it either, because the peer is active. The peer's control stream (SETTINGS, GOAWAY) has the same problem.Changes
max_buffered_frame_len(u64)toserver::Builderandclient::Builder.Frame::decode_bounded(buf, max)checks the declared length right after the type and length varints are read. If the length is over the limit, it returnsFrameError::ExceedsMaxBufferedLenbefore taking the payload.Frame::decodecalls it withu64::MAX.FrameDecodercarries the limit and does not setexpectedfor a refused frame, soFrameStreamstops buffering toward it. The error maps to a connection error of typeH3_EXCESSIVE_LOAD, per RFC 9114 §10.5.FrameStream::splitkeeps it on both halves.u64varint before converting tousize. A length that doesn't fit in ausizeis refused for every frame type, so it can't be truncated on 32-bit targets.DATAframes are streamed, not buffered, so the limit doesn't apply to them.max_field_section_size) if you'd prefer.Tests
frame.rsunit tests:expectedleft unset.DATAframe larger than the limit still decodes.FrameStream::poll_next.usize::MAXis refused.H3_EXCESSIVE_LOAD. This is checked on both server and client.I ran
cargo testwith each CI feature combination, pluscargo fmt,cargo clippy(no new warnings), the MSRV 1.74.1 checks, andduvet report. The i686 library builds, but I couldn't run the 32-bit tests locally.