pub struct Limits {
pub max_string_len: usize,
pub max_bytes_len: usize,
pub max_array_count: usize,
}Expand description
Allocation guards applied while decoding.
A u32 length field can claim up to 4 GiB, so a decoder that allocates
straight from an untrusted length is a denial-of-service target. These
limits are not part of the wire format (RFC-0002 §12): two peers with
different configurations may disagree on whether a byte stream is
acceptable, and neither is wrong.
They are additive, never a replacement for the normative check that a length
may not exceed the bytes actually remaining. Both are enforced, so the
effective ceiling is min(remaining_bytes, configured_limit).
The default is u32::MAX for every field - i.e. no restriction beyond what
the wire format itself imposes. Applications accepting bytes from the
network are expected to lower them:
use cyclone_runtime::{Limits, Reader};
let limits = Limits {
max_string_len: 1024 * 1024,
max_bytes_len: 1024 * 1024,
max_array_count: 100_000,
};
let bytes = [0u8; 0];
let reader = Reader::with_limits(&bytes, limits);
assert!(reader.is_empty());Fields§
§max_string_len: usizeLargest accepted UTF-8 byte length of a String.
max_bytes_len: usizeLargest accepted byte length of a Bytes blob.
max_array_count: usizeLargest accepted element count of an Array.