From: Christopher Faulet Date: Thu, 26 Nov 2026 19:36:17 +0000 (+0100) Subject: BUG/MINOR: http-fetch: only defrag HTX message with payload when fetching body X-Git-Url: https://git.kaiwu.me/http/%22../$%7BGITURL%7D/static/gitweb.js?a=commitdiff_plain;h=63935e2fed495756911b0e034eacb848ec989beb;p=haproxy.git BUG/MINOR: http-fetch: only defrag HTX message with payload when fetching body In smp_fetch_body() and smp_fetch_body_param(), the defragmentation was performed as soon as the HTX message was fragmented or unordered, or when its free space was wrapping, without checking if the message had a payload. In practice, it means a full HTX defragmentation was done for any bodyless request or response when the HTX message was fragmented, which may happen for instance after a header removal. Now, the defragmentation is only performed if the message contains payload, i.e. if the tail block type is higher than or equal to HTX_BLK_DATA. It is not a strict check, but it is a cheap one, and messages with a single DATA block never require a defragmentation anyway, since a single DATA block is always contiguous. This bug was introduced in 3.4 with the commit ee309bafc ("MINOR: http-fetch: Use pointer to HTX DATA block when retrieving HTX body"). It must be backported as far as 3.4. --- diff --git a/src/http_fetch.c b/src/http_fetch.c index 9aebb344b..fffbe4eaf 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -670,7 +670,9 @@ static int smp_fetch_body(const struct arg *args, struct sample *smp, const char if (!htx) return 0; - if ((htx->flags & (HTX_FL_FRAGMENTED|HTX_FL_UNORDERED)) || htx_space_wraps(htx)) + /* Only defrag if there is a payload */ + if (htx_get_tail_type(htx) >= HTX_BLK_DATA && + ((htx->flags & (HTX_FL_FRAGMENTED|HTX_FL_UNORDERED)) || htx_space_wraps(htx))) htx_defrag(htx, NULL, 0); for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { @@ -2133,7 +2135,9 @@ static int smp_fetch_body_param(const struct arg *args, struct sample *smp, cons if (!htx) return 0; - if ((htx->flags & (HTX_FL_FRAGMENTED|HTX_FL_UNORDERED)) || htx_space_wraps(htx)) + /* Only defrag if there is a payload */ + if (htx_get_tail_type(htx) >= HTX_BLK_DATA && + ((htx->flags & (HTX_FL_FRAGMENTED|HTX_FL_UNORDERED)) || htx_space_wraps(htx))) htx_defrag(htx, NULL, 0); for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {