Files
amethyst/quic
Claude 392df0384b fix(quic): HTTP/3 stream-context validation + ReceiveBuffer perf cliff
Round 3 of the audit follow-ups.

* Http3FrameReader gains a [StreamContext] parameter that enforces
  RFC 9114 §7.2 per-stream rules:
   - CONTROL: first frame MUST be SETTINGS (else H3_MISSING_SETTINGS);
     duplicate SETTINGS, DATA, HEADERS, PUSH_PROMISE all forbidden.
   - REQUEST: SETTINGS / GOAWAY / MAX_PUSH_ID / CANCEL_PUSH forbidden.
   - PUSH: similar set including PUSH_PROMISE.
   - Reserved types 0x02 / 0x06 / 0x08 / 0x09 explicitly rejected.
   - WT_BIDI_DATA / WT_UNI_DATA: reader is the wrong tool, throw.
   - UNCHECKED preserves prior test behaviour and is the default.
  WtPeerStreamDemux's CONTROL drain now constructs the reader with
  StreamContext.CONTROL, so a buggy server can no longer slip a DATA
  frame into our SETTINGS expectations and silently confuse the
  parser. The validation throws QuicCodecException, which the
  drainControlStream catch records on a new peerH3ProtocolError
  field — the QUIC layer / application reads it to close with the
  proper diagnostic instead of having the route() catch swallow it.

* ReceiveBuffer no longer coalesces overlapping segments on insert.
  Pre-fix every reorder fill allocated a fresh merged ByteArray of
  size (hi - lo) and copyInto'd each existing segment — under a 200-
  chunk reorder burst that was O(N²) bytes. The new layout keeps
  segments as a sorted, non-overlapping list (binary-searched on
  insert) and only allocates at readContiguous time, where it walks
  consecutive segments and concats them in a single pass. Adjacent
  segments are not eagerly merged — the read-side concat is bounded
  by the contiguous prefix the consumer is about to drain anyway.
  bufferedAhead becomes O(1) (cached counter) instead of O(N) sum.

* New tests cover the per-context rejection paths (CONTROL-stream
  first-frame check, DATA-on-control, SETTINGS-on-request, all four
  reserved frame types).

All 269 :quic:jvmTest tests pass. BUILD SUCCESSFUL.

https://claude.ai/code/session_01AhGvbMV8uPRse3TmAGaddM
2026-05-08 23:30:17 +00:00
..