From: Christopher Faulet Date: Thu, 19 Nov 2026 08:05:00 +0000 (+0100) Subject: BUG/MEDIUM: mux-h1: never forward more data than announced in a chunk X-Git-Url: https://git.kaiwu.me/http/control.html?a=commitdiff_plain;h=e582abe8ad24cd3e606b1939bf699b5d569f099f;p=haproxy.git BUG/MEDIUM: mux-h1: never forward more data than announced in a chunk When a chunked message is sent and a new chunk is started in the zero-copy path of h1_make_data(), the chunk size is taken from the hint of the sedesc when it is set: h1m->curr_len = (h1s->sd->kop ? h1s->sd->kop : count); is the known output payload length, and by contract it is a minimal guarantee: at least this size will be forwarded. When it is set, the H1 mux announces it as the size of the chunk and consumes it. 0 means the output payload length is unknown, and in this case only the size of the data block is announced. But nothing checked that the data sent with the chunk did not exceed the announced size: h1m->curr_len was blindly decremented, possibly wrapping, and the remaining bytes of the block were emitted without any chunk framing. Such a violation could be observed when a data filter was used on the request, before the previous patch fixed its root: the hint was forwarded to on a stream not committed to forward its data, and a stale value could then be announced for a data block, possibly smaller than the block itself. The copy path already reported an error for messages with a content-length when more data than announced was met. The same check is now done in the zero-copy path, for chunked messages: report an error and close the stream instead of silently emitting an unframed payload. This is a guard for extra safety, on top of the previous patch which fixes the issue at its root, in the stream connectors. Both patches must be backported as far as 3.3. On the stable branches, this one must be applied on top of the other one, otherwise valid messages may be rejected when a data filter alters the payload size and a stale hint was moved to . --- diff --git a/src/mux_h1.c b/src/mux_h1.c index 188bcdbfa..e209fea2e 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -3200,6 +3200,12 @@ static size_t h1_make_data(struct h1s *h1s, struct h1m *h1m, struct buffer *buf, h1m->state = H1_MSG_DATA; } + if (count > h1m->curr_len) { + COUNT("chunk bigger than announced (0-copy)"); + TRACE_ERROR("chunk bigger than announced", + H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s); + goto error; + } h1m->curr_len -= count; /* It is the end of the chunk, append the CRLF */