From: Christopher Faulet Date: Tue, 1 Dec 2026 11:07:51 +0000 (+0100) Subject: MINOR: mux-h1: never negotiate a zero-sized chunk in h1_nego_ff() X-Git-Url: https://git.kaiwu.me/web/%7Bsubstring-before(@doc,%20'.xml')%7D.html?a=commitdiff_plain;h=07b1d29974f177ab7215fec1f6835e0b6e6b8a5a;p=haproxy.git MINOR: mux-h1: never negotiate a zero-sized chunk in h1_nego_ff() In h1_nego_ff(), with NEGO_FF_FL_EXACT_SIZE and a chunked message in CHUNK_CRLF/CHUNK_SIZE state, a producer calling with == 0 makes h1_make_chunk() emit "0\r\n", i.e. the last-chunk, prematurely ending the message for the peer. No case was found where it happens. The stream connectors (sc_conn_recv() and sc_applet_recv()) only call the producers to fast-forward data when there is something to forward. But it is not true for all producers. For instance, haterm may negotiate with == 0 when its splicing pipe still contains data while everything was already produced. In that case, the message is already finished, and the fast-forwarding is disabled because of the message state. But nothing in h1_nego_ff() prevents it for a chunked message. So let's harden it: when is 0, no chunk is started. The iobuf is still set up as usual, so the producer can safely use it, and nothing is forwarded. The IOBUF_FL_NO_FF flag is not set because == 0 is a transient condition, and this flag would permanently disable the fast-forwarding for the stream. --- diff --git a/src/mux_h1.c b/src/mux_h1.c index c8ee5b011..b77f70080 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -5230,7 +5230,6 @@ static size_t h1_nego_ff(struct stconn *sc, struct buffer *input, size_t count, TRACE_ENTER(H1_EV_STRM_SEND, h1c->conn, h1s, 0, (size_t[]){count}); - if (global.tune.no_zero_copy_fwd & NO_ZERO_COPY_FWD_H1_SND) { h1s->sd->iobuf.flags |= IOBUF_FL_NO_FF; goto out; @@ -5271,12 +5270,19 @@ static size_t h1_nego_ff(struct stconn *sc, struct buffer *input, size_t count, else { BUG_ON(h1m->state != H1_MSG_CHUNK_CRLF && h1m->state != H1_MSG_CHUNK_SIZE); if (flags & NEGO_FF_FL_EXACT_SIZE) { - if (!h1_make_chunk(h1s, h1m, count)) { - h1s->sd->iobuf.flags |= IOBUF_FL_FF_BLOCKED; - goto out; + /* Never emit a zero-sized chunk. It is the + * last-chunk, it would prematurely end the + * message. With == 0, nothing will be + * forwarded, so no chunk is started. + */ + if (count) { + if (!h1_make_chunk(h1s, h1m, count)) { + h1s->sd->iobuf.flags |= IOBUF_FL_FF_BLOCKED; + goto out; + } + h1m->curr_len = count; + h1s_consume_kop(h1s, h1m->curr_len); } - h1m->curr_len = count; - h1s_consume_kop(h1s, h1m->curr_len); } else { /* The producer does not know the chunk size, thus this will be emitted at the