From 1ec2f29ac02e66dcd1e989d839873ffa7b61cc8a Mon Sep 17 00:00:00 2001
From: Andrea Cocito <andrea@cocito.eu>
Date: Fri, 27 Nov 2026 16:19:57 +0100
Subject: [PATCH 1/2] BUG/MEDIUM: mux-h1: defer read0 while input is buffered
To: haproxy@formilux.org
Cc: cfaulet@haproxy.com

On kqueue, backend EOF may be reported while the H1 mux still has response
body bytes in h1c->ibuf. With a flow-controlled H2 or H3 consumer,
h1_fastfwd() can forward only part of those bytes, then observe read0 while
h1m->curr_len is still nonzero. It reports a truncated response and aborts
the client stream even though the remaining bytes are already in memory.
In the affected FreeBSD/H3 workload, 16 KiB responses reached the client
as 16,066 bytes and curl reported a partial transfer.

Classify read0 in this fast-forward path only after h1c->ibuf is empty.
Keep fast forwarding active so a later consumer window update can drain the
buffer. The existing EOS/EOI and genuine-truncation decisions then run with
the correct remaining message length.

A VTest reproducer holds the H2 window closed until the backend closes,
then opens it in steps to force read0 with buffered H1 input. It fails on
unpatched macOS and FreeBSD kqueue builds and passes with the fix. The same
fix passes on the affected 3.4.7 source and current 3.4.9 maintenance source.
A genuinely short Content-Length response still forwards exactly the sent
bytes and resets the H2 stream.

This patch must be backported to 3.4. Older branches have not been tested.
---
 src/mux_h1.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/mux_h1.c b/src/mux_h1.c
index 136b850a0..582872e37 100644
--- a/src/mux_h1.c
+++ b/src/mux_h1.c
@@ -5635,7 +5635,8 @@ static int h1_fastfwd(struct stconn *sc, unsigned int count, unsigned int flags)
 		}
 	}
 
-	if (conn_xprt_read0_pending(h1c->conn)) {
+	/* Buffered input must be forwarded before judging the message at EOF. */
+	if (!b_data(&h1c->ibuf) && conn_xprt_read0_pending(h1c->conn)) {
 		se_fl_set(h1s->sd, SE_FL_EOS);
 		TRACE_STATE("report EOS to SE", H1_EV_STRM_RECV, h1c->conn, h1s);
 		if (h1m->state >= H1_MSG_DONE || !(h1m->flags & H1_MF_XFER_LEN)) {
-- 
2.33.0

