Skip to main content

DEFAULT_UNKNOWN_FIELD_LIMIT

Constant DEFAULT_UNKNOWN_FIELD_LIMIT 

Source
pub const DEFAULT_UNKNOWN_FIELD_LIMIT: usize = 1_000_000;
Expand description

Default limit on unknown fields decoded per top-level decode: 1,000,000.

Bounds the number of UnknownField values the decoder will materialize in a single top-level decode, independent of the input size. Without this bound, wire data can force allocation far in excess of its own size: every 2-byte unknown varint field materialises a ~40-byte UnknownField, a ~20× amplification, so a 64 MiB payload of unknown fields would otherwise force over 1 GiB of heap. The count limit caps that overhead at roughly limit × 40 bytes (~40 MB at the default); unknown length-delimited payload bytes are not counted against the limit because they are already bounded by the input size, which DecodeOptions::with_max_message_size governs.

A million unknown fields is far more than any realistic forward-compatibility scenario needs. Raise the limit with DecodeOptions::with_unknown_field_limit if you decode trusted messages that legitimately carry more (e.g. a proxy forwarding messages with a huge unpacked repeated field from a much newer schema).