Skip to main content

DEFAULT_ELEMENT_BUDGET

Constant DEFAULT_ELEMENT_BUDGET 

Source
pub const DEFAULT_ELEMENT_BUDGET: usize = _; // 1_048_576usize
Expand description

Default ceiling on the total number of Value elements a single TlvReader::read_value call may materialise.

Tree-builder decoding allocates one Value (and, inside containers, one (Tag, Value) pair) per element. A tiny scalar such as a boolean costs a single wire byte but expands to a heap-resident Value, so an input packed with millions of one-byte scalars can amplify into a large allocation. This budget bounds that amplification: a decode that would produce more than this many elements fails with Error::ElementBudgetExceeded.

The default is deliberately generous (1,048,576 elements) — far above any legitimate Matter payload, which is itself bounded by the protocol’s message-size limits — so it only ever trips on adversarial input. Callers that need a tighter or looser bound can set their own via TlvReader::with_element_budget.