From: Martin Mirchev Date: Wed, 18 Nov 2026 12:39:28 +0000 (+0800) Subject: BUG/MINOR: sample: do not parse compressed gRPC messages in ungrpc X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/static/gitweb.js?a=commitdiff_plain;h=9559d681e94c8b4f116c9fb03e6d1ec0b0e98d32;p=haproxy.git BUG/MINOR: sample: do not parse compressed gRPC messages in ungrpc 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. --- diff --git a/src/sample.c b/src/sample.c index eddef4be3..a47066d99 100644 --- a/src/sample.c +++ b/src/sample.c @@ -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;