]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: flt-decomp: don't leave an empty DATA block when draining
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 30 Nov 2026 13:36:33 +0000 (14:36 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 30 Nov 2026 15:03:42 +0000 (16:03 +0100)
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.

src/flt_decomp.c

index bd33ec7b54dfeb14c91b35cbf54abe8536bd8b4d..7a21d3b83968f439ccc4db85fa8cc70c0d33ff9e 100644 (file)
@@ -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;