]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: flt-decomp: accept an empty payload
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 2 Dec 2026 14:30:37 +0000 (15:30 +0100)
committerOlivier Houchard <cognet@ci0.org>
Wed, 2 Dec 2026 14:33:02 +0000 (15:33 +0100)
Some servers announce a content-encoding on a message with an empty
payload, e.g. a chunked response with only the last chunk. No data are
passed to the decoder in this case, so it never reports the end of the
compressed stream: the end of the message was held forever, and since
truncated payloads are detected, it was reported as an error.

Now the filter remembers when payload data were received. When the end
of the payload is reached without any, there is nothing to decompress
and the decompression is considered as finished, so the empty message is
forwarded. The filter was introduced in 3.5-dev6, so no backport is
needed.

src/flt_decomp.c

index 3fe8d51b8e245e4ebb91898a8f94a5c5083e30b7..46c6099f96221cfbe280ac20bc9514b5918c7c1f 100644 (file)
@@ -34,6 +34,7 @@
 
 #define DECOMP_STATE_PROCESSING 0x01
 #define DECOMP_STATE_EOM_SEEN   0x02
+#define DECOMP_STATE_DATA_SEEN  0x04 /* some payload data were received */
 
 const char *decomp_req_flt_id = "decomp-req filter";
 const char *decomp_res_flt_id = "decomp-res filter";
@@ -268,6 +269,7 @@ static int decomp_stream_blk(struct stream *s, struct filter *f, struct channel
                        case HTX_BLK_UNUSED:
                                goto next;
                        case HTX_BLK_DATA:
+                               st->flags |= DECOMP_STATE_DATA_SEEN;
                                if (blk->flags & HTX_BLK_FL_EOM) {
                                        blk->flags &= ~HTX_BLK_FL_EOM;
                                        st->flags |= DECOMP_STATE_EOM_SEEN;
@@ -349,6 +351,14 @@ static int decomp_stream_blk(struct stream *s, struct filter *f, struct channel
                                        /* there is still pending data that we need to drain */
                                        break;
                                }
+                               if (!(st->flags & DECOMP_STATE_DATA_SEEN)) {
+                                       /* The end of the payload is reached without any
+                                        * data. There is nothing to decompress, so it is
+                                        * an empty payload, not a truncated one. The
+                                        * decompression is finished.
+                                        */
+                                       st->decomp_ctx->flags |= DECOMP_CTX_FL_DONE;
+                               }
                                if (!(st->decomp_ctx->flags & DECOMP_CTX_FL_DONE)) {
                                        char *data = "";