]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: http-fetch: only defrag HTX message with payload when fetching body
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 26 Nov 2026 19:36:17 +0000 (20:36 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 27 Nov 2026 11:01:36 +0000 (12:01 +0100)
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.

src/http_fetch.c

index 9aebb344b3ecd2bac9a0ef1cf25e93295189b5aa..fffbe4eaff2f4648d3797607be357e3e4aa3b8a0 100644 (file)
@@ -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)) {