]> git.kaiwu.me - haproxy.git/commit
MINOR: flt-http-comp: size the compression reserve using SLZ_MAX_OVERHEAD()
authorWilly Tarreau <w@1wt.eu>
Sun, 1 Nov 2026 15:36:20 +0000 (16:36 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 3 Nov 2026 08:40:36 +0000 (09:40 +0100)
commit7a65e029f1a99b0127422107503c06b9dfc931b5
tree2b410fd02addfc0d312dab921d5fc647309629fd
parent00bb955ca96e3f499596e98e950e500d680c2018
MINOR: flt-http-comp: size the compression reserve using SLZ_MAX_OVERHEAD()

htx_compression_buffer_init() reserves room for the deflater's output based
on what it would emit as stored blocks. libslz now publishes in slz.h the
room each call to slz_encode() needs beyond its input length,
SLZ_MAX_OVERHEAD(len), which includes the stored blocks, the end of the
stream, the bits queued by previous calls and the up to 40 bytes its fixed
huffman encoding may lag behind stored blocks. Let's use it so that the
reserve follows slz's own settings instead of a local estimate.

All the DATA blocks of a pass are queued by the slz backend and compressed
in a single call when the last one is flushed, so the call covers at most
the whole buffer. The reserve is thus based on the buffer size, which keeps
it constant (52 bytes for buffers up to 64 kB), plus 14 bytes for the finish
(queue, last block and gzip trailer, a flush needs 10) and 10 bytes for the
gzip header: 76 bytes for 16 kB buffers.

The previous computation is kept for zlib, which publishes no such bound,
and when linking with an older external libslz which doesn't define the
macro. In all cases the result of htx_replace_blk_value() remains checked
since commit 5ab337485 ("BUG/MEDIUM: flt-http-comp: check the block
returned by htx_replace_blk_value()"). Crafted bodies made of runs of
literals >= 144 separated by short references, as well as random data,
sent in chunks of 256 bytes to 64 kB, all decompress correctly.

This is not a bug fix, only a way to better tie haproxy to slz's settings,
and it must not be backported.
src/flt_http_comp.c