Skip to main content

validate_bounded_len

Function validate_bounded_len 

Source
pub fn validate_bounded_len<R>(
    source: &R,
    label: &str,
    len: usize,
    min_element_size: usize,
) -> Result<(), DeserializationError>
where R: ByteReader,
Expand description

Validates that a serialized length fits both the reader budget and remaining input.

This guards against malicious length prefixes that would otherwise cause a compact payload to be amplified into a large allocation.

§Errors

Returns DeserializationError::InvalidValue if:

  • len exceeds the number of elements the reader’s remaining budget allows.
  • len * min_element_size overflows.
  • The source does not hold len * min_element_size more bytes.