]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: sample: do not parse compressed gRPC messages in ungrpc
authorMartin Mirchev <mirchevmartin2203@gmail.com>
Wed, 18 Nov 2026 12:39:28 +0000 (20:39 +0800)
committerFrederic Lecaille <flecaille@haproxy.com>
Thu, 19 Nov 2026 09:57:16 +0000 (10:57 +0100)
sample_conv_ungrpc() skips the 5-byte gRPC message header without looking
at its Compressed-Flag byte, so a message whose payload is compressed
(flag 1) is handed to the protobuf parser as if it were plain protobuf,
and so is a message with an invalid flag value. A request body
"01 00 00 00 02 08 2a" (compressed flag, 2-byte payload) returns 42 from
"req.body,ungrpc(1,uint32)", exactly as the uncompressed one does, while
the real field value would only appear after decompression.

Skip compressed messages, as their payload cannot be parsed, and stop on
a flag other than 0 or 1 since the gRPC framing is then invalid.

This should be backported to all stable versions.

src/sample.c

index eddef4be3e34386874db1cce5900e15c81c20270..a47066d99f1862e4d1ad689d81f85a276542b7dc 100644 (file)
@@ -4480,6 +4480,12 @@ static int sample_conv_ungrpc(const struct arg *arg_p, struct sample *smp, void
        while (grpc_left > GRPC_MSG_HEADER_SZ) {
                size_t grpc_msg_len, left;
                unsigned char *msg_end;
+               unsigned char compressed;
+
+               /* the Compressed-Flag may only be 0 or 1 */
+               compressed = *pos;
+               if (compressed > 1)
+                       return 0;
 
                grpc_msg_len = left = ntohl(read_u32(pos + GRPC_MSG_COMPRESS_FLAG_SZ));
 
@@ -4498,7 +4504,8 @@ static int sample_conv_ungrpc(const struct arg *arg_p, struct sample *smp, void
                 */
                msg_end = pos + grpc_msg_len;
 
-               if (protobuf_field_lookup(arg_p, smp, &pos, &left))
+               /* a compressed message cannot be parsed as protobuf, skip it */
+               if (!compressed && protobuf_field_lookup(arg_p, smp, &pos, &left))
                        return 1;
 
                pos = msg_end;