From: Christopher Faulet Date: Mon, 30 Nov 2026 13:36:33 +0000 (+0100) Subject: BUG/MINOR: flt-decomp: don't leave an empty DATA block when draining X-Git-Url: https://git.kaiwu.me/http/%22..//%22data:,/%22?a=commitdiff_plain;h=682ba15b3fecf6567f52fc6028c703fdf59252ac;p=haproxy.git BUG/MINOR: flt-decomp: don't leave an empty DATA block when draining When there is not enough room to drain the decompressed data, decomp_stream_blk_drain() replaces the fully consumed part of the DATA block with the drained data. But if nothing could be drained, i.e. the drainable length is 0, and the block was fully consumed, the block was left empty in the HTX message. Similarly, when the function is called without a block, because there is no DATA block to drain into, a zero-sized DATA block could be added if nothing was drainable. An empty DATA block is not supposed to remain in an HTX message. For a chunked message, mux-h1 would emit a zero-sized chunk, i.e. the last-chunk, prematurely ending the message for the client and making it interpret any remaining data as a new message (response splitting). So, when the block is fully consumed and nothing can be drained in its place, the block is now removed instead of being emptied, taking care of the EOM flag, if the block was carrying it. And when there is no block to drain into, nothing is added if nothing is drainable. This latter case is handled by htx_add_last_data() which refuses empty data. This is a latent bug, no way was found to trigger it with a well-behaving client or server, but the HTX API is about to enforce the no-empty-data-block invariant, so the filter must behave accordingly. No backport needed. --- diff --git a/src/flt_decomp.c b/src/flt_decomp.c index bd33ec7b5..7a21d3b83 100644 --- a/src/flt_decomp.c +++ b/src/flt_decomp.c @@ -147,6 +147,16 @@ static int decomp_stream_blk_drain(struct stream *s, struct filter *f, struct ch if (blk) { struct htx_blk *new_blk; + /* If the block is fully consumed and there is nothing to write + * in its place, it must be removed. + */ + if (!drainable && htx_get_blksz(*blk) == consumed) { + if ((*blk)->flags & HTX_BLK_FL_EOM) + st->flags |= DECOMP_STATE_EOM_SEEN; + *blk = htx_remove_blk(htx, *blk); + goto update; + } + new_blk = htx_replace_blk_value(htx, *blk, ist2(offset, consumed), ist2(st->decomp_ctx->drain, drainable)); if (!new_blk) { /* The expansion failed. The space was checked above so this @@ -176,6 +186,7 @@ static int decomp_stream_blk_drain(struct stream *s, struct filter *f, struct ch return 0; } + update: flt_update_offsets(f, chn, drainable - consumed); st->decomp_ctx->drain += drainable; st->decomp_ctx->drain_len -= drainable;