Skip to content

mux-h2: a short read of 25..=32 octets disconnects a valid client, because the preface guard compares against a 24-octet constant #1487

Closed

Description

@FlorentinDUBOIS

ConnectionH2::handle_read's early-preface guard rejects any accumulated window longer than the 24-octet preface, so a valid client whose read lands mid-SETTINGS-header is disconnected.

The guard

In the short-read branch of ConnectionH2::handle_read — reached when size < amount, i.e. the read did not fill the request:

self.stream_table.set_expect_read(Some((stream_id, amount - size)));
if let (H2State::ClientPreface, Position::Server) = (&self.state, &self.position) {
    let i = kawa.storage.data();
    if !b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".starts_with(i) {
        debug!("{} EARLY INVALID PREFACE: {:?}", log_context!(self), i);
        return self.force_disconnect();
    }
}

i is the whole accumulated buffer, and the window requested is CLIENT_PREFACE_SIZE, defined as 24 + parser::FRAME_HEADER_SIZE = 33. The constant is 24 octets.

constant.starts_with(i) asks whether i is a prefix of the constant. Once i.len() > 24 that is false for every possible input, including a byte-perfect preface followed by a byte-perfect SETTINGS header. The guard then calls force_disconnect().

So the guard is correct only while the client has sent 24 octets or fewer. Between 25 and 32 it rejects unconditionally.

Measured

Driving ConnectionH2 as a server with a fixed socket_read chunk size, byte-perfect preface + SETTINGS in all cases:

chunk size result
1, 25, 26, 32 MuxResult::CloseSession, 0 frames emitted
12, 23, 24, 33, 64 handshake completes, 3 frames

12 and 23 survive because the accumulated window is still ≤ 24 when the guard runs. 33 and 64 survive because the read is not short, so the guard is not reached at all. 1 fails because accumulation crosses 24 before the request is filled.

Why this matters in production

Nothing about a TCP or TLS read guarantees it lands on the 24-octet boundary. A read() returning 25..=32 octets is ordinary — a small segment, a TLS record split, a client that writes the preface and SETTINGS in one write() that the kernel delivers in two pieces. Every one of those is a conforming client that Sōzu closes without a GOAWAY.

The debug! says EARLY INVALID PREFACE, so the operator-visible signal names the client as the offender.

Fix

Compare only the part of the window the constant can cover:

if !b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".starts_with(&i[..i.len().min(24)]) {

A regression test wants the chunk-size axis above, not a single size: the defect is invisible at 24 and at 33, which are the two sizes a hand-written test is most likely to pick.

Provenance

Found by the H2 deterministic simulator while building its read-fragmentation axis (#1359 C4). The simulator's H2Harness::bootstrap delivers the preface whole and documents why, so the carve-out is explicit rather than silent; every byte after the handshake goes through fragmentation. The guard dates to de87c9450 (2026-03-09).

Activity

  1. added a commit that references this issue on Sep 24, 2026
    fa0b93a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions