From: Olivier Houchard Date: Tue, 17 Nov 2026 14:06:51 +0000 (+0100) Subject: BUG/MEDIUM: htx: never merge the next DATA block into the referenced one on defrag X-Git-Tag: v3.5-dev13~32 X-Git-Url: https://git.kaiwu.me/http/%7B@url%7D?a=commitdiff_plain;h=4219755072fd5f3637a159750f3e9a7a64c4468f;p=haproxy.git BUG/MEDIUM: htx: never merge the next DATA block into the referenced one on defrag When htx_defrag() is called with a referenced DATA block, this block is copied as a new block to preserve it. But the DATA block following it, if any, is then copied using __htx_add_data_type_atonce(), which appends it to the tail block, i.e. to the referenced block itself. The returned block is thus larger than requested by and contains the next block's data. The compression filter, which continues with the block following the one it replaced with htx_replace_blk_value(), then skips these data and forwards them uncompressed in the middle of the compressed stream. This can be triggered with a Lua filter appending data at the end of a response (HTTPMessage:append()) before the compression filter: the appended data are added in a new DATA block, and when the compressed output of the previous block is larger than the input and requires a defragmentation, the appended data are emitted as-is and the response is corrupted. Let's never merge a DATA block into the referenced block. This was introduced by commit 0c6f2207f ("MEDIUM: htx: Refactor htx defragmentation to merge data blocks"). It should be backported to 3.4. --- diff --git a/src/htx.c b/src/htx.c index 5583cd5a2..68cd003ae 100644 --- a/src/htx.c +++ b/src/htx.c @@ -44,10 +44,10 @@ static inline __attribute__((always_inline)) int htx_hdrs_too_big(const struct h * part. A temporary buffer is used to do so. This function never fails. Most of * time, we need keep a ref on a specific HTX block. Thus is is set, the * pointer on its new position, after defrag, is returned. If is a DATA - * block, no merge with any previous DATA block is performed. In addition, if - * the size of the block must be altered, info must be provided (!= - * 0). But in this case, it remains the caller responsibility to update the - * block content. + * block, no merge with any previous nor next DATA block is performed. In + * addition, if the size of the block must be altered, info must be + * provided (!= 0). But in this case, it remains the caller responsibility to + * update the block content. */ struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk, uint32_t blkinfo) { @@ -77,7 +77,8 @@ struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk, uint32_t blkinf switch (type) { case HTX_BLK_DATA: case HTX_BLK_RAW_DATA: - if (blk != oldblk) { + if (blk != oldblk && + (blkpos == (uint32_t)-1 || htx_get_tail(tmp) != (int32_t)blkpos)) { newblk = __htx_add_data_type_atonce(tmp, htx_get_blk_value(htx, oldblk), type); break; }