Skip to content

fix(proto): bound assembler chunk count (port of quinn RUSTSEC-2026-0185 fixes) - #828

Closed
kixelated wants to merge 3 commits into
n0-computer:mainfrom
moq-dev:n0/assembler-chunk-cap
Closed

kixelated wants to merge 3 commits into
n0-computer:mainfrom
moq-dev:n0/assembler-chunk-cap

Conversation

@kixelated

Copy link
Copy Markdown
Contributor

Description

Ports quinn's fix for RUSTSEC-2026-0185 (CVE-2026-25800, GHSA-4w2j-m93h-cj5j) to noq-proto. A peer sending small gapped STREAM or CRYPTO frames can make the Assembler buffer an unbounded number of chunks while the reader waits for the missing prefix. noq-proto 1.3.0 predates the fix, and cargo audit cannot flag it because the crate is renamed.

Three commits, one per quinn commit on the 0.11.x line, authorship kept:

  1. quinn-rs/quinn#2694 (fed0321a, quinn-proto 0.11.15): Assembler::insert returns TooManyChunks when more than 1024 chunks remain after defragmenting; the stream and CRYPTO paths close the connection with INTERNAL_ERROR.
  2. quinn-rs/quinn#2789 (4b88c940, 0.11.17): the cap in (1) is only checked when over-allocation is high, so gapped frames whose allocation equals their length bypass it. Also compact once the count passes 2x the cap.
  3. quinn-rs/quinn#2814 (c3f8b098, 0.11.18): coalesce small contiguous chunks during defragment, so (2) does not reject lossless data on a large stream_receive_window with a slow reader.

(1) alone is bypassable, and (2) without (3) can reject a legitimate stream, so they go together. The result matches quinn-proto 0.11.18's assembler logic; the heap-to-VecDeque refactor on quinn main is not included.

API Changes

None. Wire: a peer that exceeds the chunk cap is closed with INTERNAL_ERROR.

Notes & open questions

  • noq's defragment starts at bytes_read where quinn starts at 0. The three commits apply unchanged on top.
  • quinn's tests are kept, plus .unwrap() on existing insert calls, including the proptest.

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All API changes documented.
  • This PR was created by a human that thought critically about the
    proposed change and wrote an as clear and concise description as
    they could.
  • This PR isn't slop, and is carefully crafted to do have the
    intented effect.
  • cargo make passes locally. (cargo test -p noq-proto and cargo clippy -p noq-proto --all-targets -- -D warnings pass.)

Opened on behalf of the moq-dev/noq fork, which carries the same commits.

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

djc and others added 3 commits September 30, 2026 09:40
Port of quinn-rs/quinn@fed0321a (quinn-rs/quinn#2694, RUSTSEC-2026-0185):
a peer sending small gapped STREAM or CRYPTO frames could make the
assembler buffer an unbounded number of chunks. After defragmenting,
more than 1024 chunks now closes the connection with INTERNAL_ERROR.

Co-Authored-By: Luke Curley <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Port of quinn-rs/quinn@4b88c940 (quinn-rs/quinn#2789). The cap above
was only checked inside the over-allocation branch, so gapped frames
whose allocation matches their length, or frames handled entirely by
the unordered dedup loop, still grew the chunk count without bound.
Compact once the count passes twice the cap and reject only if
compaction cannot bring it back under.

Co-Authored-By: Luke Curley <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Port of quinn-rs/quinn@c3f8b098 (quinn-rs/quinn#2814). defragment now
combines contiguous chunks smaller than buffered / MAX_CHUNKS, so a
large stream_receive_window with a slow in-order reader no longer trips
TooManyChunks on lossless data. Chunks above the minimum size are left
alone so they are not copied on every compaction.

Co-Authored-By: Luke Curley <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@n0bot n0bot Bot added this to iroh Sep 30, 2026
trancong12102 added a commit to aislopware/slopty that referenced this pull request Oct 2, 2026
noq-proto 1.3.0 forked before quinn-proto bounded how many chunks a stream's or CRYPTO's
assembler holds, so a peer sending small frames with gaps could grow a client's or a worker's
memory without limit, and the crate's new name hides the advisory from cargo audit. Take
n0-computer/noq#828 as patch 18, unchanged: insert refuses past 1024 chunks left after
defragmenting, which closes the connection with INTERNAL_ERROR, and contiguous small chunks
coalesce so a slow reader on a large window is not refused.

Co-Authored-By: Claude Code
miraclx added a commit to theia-hq/bifrost that referenced this pull request Oct 8, 2026
* Bound what a QUIC peer can make an iroh endpoint buffer

Take noq-proto from the head of n0-computer/noq#828, which ports quinn's
cap on out-of-order chunks per stream (RUSTSEC-2026-0185), until n0
releases it. Every bifrost-iroh bind now applies one QUIC config: no
unidirectional streams, no application datagrams, and a 16 MiB
connection receive window.

* Tell embedders to carry the noq-proto patch themselves

* Drain what each stream sent in the connection budget test

Read back exactly the bytes each stream took, until past the eighth of
the window that makes noq announce freed room, so a stream that stalled
early cannot hang the drain. Stop opening streams once one takes nothing
with the window nearly full. Count both stream directions in the
window's why-comment, and say the limits do not reach iroh's own
address-discovery connection to a relay.
miraclx added a commit to theia-hq/tightbeam that referenced this pull request Oct 8, 2026
* Take the bounded noq-proto and bifrost's QUIC limits

Pin bifrost 3d1f79e, where every bifrost-iroh bind allows a peer no
unidirectional streams, no datagrams, and 16 MiB of unread stream data
per connection. Patch noq-proto to the head of n0-computer/noq#828,
which ports quinn's cap on out-of-order chunks per stream
(RUSTSEC-2026-0185): cargo honours a patch only at the workspace root,
so bifrost's own patch does not reach this build. Allow that one git
source in deny.toml until n0 releases the fix.

* Check advisories in CI and watch the crates our forks copy

A daily, push and pull-request workflow runs cargo-deny's advisory
check, pinned to a cargo-deny that loads CVSS 4.0 entries, and the fork
watch from bifrost, which fails when an advisory filed against quinn,
quinn-proto or quinn-udp has no row saying how our fork stands. Move
rustls to 0.23.45 (RUSTSEC-2026-0285). Ignore the unmaintained notices
for paste and proc-macro-error2, build-time proc macros, with their
reasons.

* Tell workspaces that depend on tightbeam to patch noq-proto
miraclx added a commit to theia-hq/swoosh that referenced this pull request Oct 9, 2026
* Take the bounded noq-proto and check advisories in CI

Pin bifrost 3d1f79e, tightbeam de0b58d and services f1a2ef6. bifrost
now allows a peer no unidirectional streams, no datagrams, and 16 MiB
of unread stream data per connection; services builds russh without
rsa, so the rsa crate (RUSTSEC-2023-0071) leaves the graph. Patch
noq-proto to the head of n0-computer/noq#828, which ports quinn's cap
on out-of-order chunks per stream (RUSTSEC-2026-0185): cargo honours a
patch only at the workspace root, so the siblings' patches do not reach
this build. Allow that one git source in deny.toml until n0 releases
the fix.

Add a daily, push and pull-request workflow that runs cargo-deny's
advisory check, pinned to a cargo-deny that loads CVSS 4.0 entries,
and the fork watch from bifrost, which fails when an advisory filed
against quinn, quinn-proto or quinn-udp has no row saying how our fork
stands. Move rustls to 0.23.45 (RUSTSEC-2026-0285). Ignore the
unmaintained notices for paste and proc-macro-error2, build-time proc
macros, with their reasons.

* Say what a machine could do to swoosh before the bounded noq-proto
@thtbee

thtbee commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for porting these. The first two commits landed via #823 and shipped in 1.4.0, but the coalescing one didn't, so on 1.4.0 a receiver that stops reading for a bit gets disconnected with "too many gaps in stream buffer" after 2,048 packets, with no actual gaps. Packet-sized chunks get marked defragmented and are never merged again, so compaction can't get under MAX_CHUNKS.

This branch fixes it and matches quinn 0.11.18. It only needs a rebase down to the last commit. A 1.4.x patch with it would be great.

Repro

Fails on 1.4.0 and main (07047ff) with rejected after 2048 packets, passes here:

#[test]
fn in_order_stream_is_not_rejected() {
    let mut x = Assembler::new();
    let data = Bytes::from(vec![0; 1200]);
    let mut offset = 0u64;
    for i in 0..14000 {
        if x.insert(offset, data.clone(), 1200).is_err() {
            panic!("rejected after {i} packets");
        }
        offset += 1200;
    }
}

Not covered here: quinn-rs/quinn#2955 (still open upstream) and the unordered-mode bug in #865.

@flub

flub commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Hi @thtbee, it feel free to take over this and create a PR for the remaining commit in a new PR. Just mention that it replaces this one. Thanks!

@thtbee

thtbee commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Thanks @flub, opened #866 for the remaining commit, rebased onto the VecDeque change from #823.

@flub

flub commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

replaced, see comments above for links

@flub flub closed this Oct 27, 2026
@github-project-automation github-project-automation Bot moved this from 🚑 Needs Triage to ✅ Done in iroh Oct 27, 2026
danielpetri1 pushed a commit to danielpetri1/noq that referenced this pull request Oct 27, 2026
…#866)

## Description

Replaces n0-computer#828, as discussed there. The first two commits of that PR
landed in n0-computer#823, so this is the remaining one: the port of
quinn-rs/quinn#2814, adapted to the sorted `VecDeque` from n0-computer#823.

Without it, 1.4.0 can close a connection with "too many gaps in stream
buffer" when a reader falls about 2,048 packets behind, even with no
gaps. Packet-sized chunks get marked defragmented and are never merged
again, so compaction can't get back under `MAX_CHUNKS`. `defragment` now
also merges contiguous chunks smaller than `buffered / MAX_CHUNKS` (at
least 128 bytes), like quinn.

Brings over quinn's two tests. `ordered_lossless_stream_is_not_rejected`
fails on `main` and passes here.

## API Changes

None.

## Notes & open questions

quinn-rs/quinn#2955 (contiguous data behind a single gap under sustained
loss) is still open upstream and isn't covered here. This touches
`defragment` like n0-computer#867 (the fix for n0-computer#865), so whichever lands second
needs a small rebase.

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All API changes documented.
- [x] `cargo make` passes locally.

Co-authored-by: Eanna Lyons <[email protected]>
Co-authored-by: Luke Curley <[email protected]>
Co-authored-by: Floris Bruynooghe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

6 participants