QGrpcHttp2Channel: reject messages exceeding a configurable size limit
The gRPC frame parser accepted any declared frame length up to 2^32
bytes without validation, allowing a malicious peer to trigger a
multi-gigabyte allocation with a single crafted 5-byte header.
Introduce a maximum receive message size that is enforced in
GrpcDataParser::parseNextFrame() before any payload memory is allocated.
The default is 4 MiB, matching the gRPC C++ reference implementation and
the gRPC specification. A value of 0 disables the limit.
The limit is exposed as setMaximumReceiveMessageSize() on both
QGrpcChannelOptions and QGrpcCallOptions. Call options take precedence
over channel options. The environment variable
QT_GRPC_MAXIMUM_RECEIVE_MESSAGE_SIZE provides a highest-priority
override useful for operational purposes and backporting without API
changes. It is sampled once at channel construction to avoid negative
effects on parallel processing as qEnvironmentVariable is acquiring a
global lock.
The same limit is applied to the decompressed output of compressed
frames to guard against compression bombs.
As a side effect, this also resolves a qsizetype overflow on 32-bit
platforms: the configured limit is clamped to GrpcMaxPayloadSize, which
is itself bounded by qsizetype headroom.
Backport to 6.11 and 6.8 manually: pick the environment variable and the
GrpcMaxPayloadSize size cap.
[ChangeLog][QtGrpc][QGrpc{Call,Channel}Options] Added
setMaximumReceiveMessageSize() to limit the size of incoming messages.
The default is 4 MiB, matching the gRPC specification. The environment
variable QT_GRPC_MAXIMUM_RECEIVE_MESSAGE_SIZE provides a global override
without requiring code changes.
Task-number: QTBUG-145258
Task-number: QTBUG-145399
Fixes: QTBUG-146592
Change-Id: I0f99293252d19992f5ea7b42dd8a427f6bf3eced
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>