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.
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));
*/
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;