pub struct Limits {
pub max_file_size: usize,
pub max_line_length: usize,
pub max_indent_depth: usize,
pub max_nodes: usize,
pub max_aliases: usize,
pub max_columns: usize,
pub max_nest_depth: usize,
pub max_block_string_size: usize,
pub max_object_keys: usize,
pub max_total_keys: usize,
pub max_total_ids: usize,
pub timeout: Option<Duration>,
}Expand description
Configurable limits for parser security.
These limits protect against denial-of-service attacks and memory exhaustion by bounding the resources consumed during parsing.
Fields§
§max_file_size: usizeMaximum file size in bytes (default: 1GB).
max_line_length: usizeMaximum line length in bytes (default: 1MB).
max_indent_depth: usizeMaximum indent depth (default: 50).
max_nodes: usizeMaximum number of nodes (default: 10M).
max_aliases: usizeMaximum number of aliases (default: 10k).
max_columns: usizeMaximum columns per schema (default: 100).
max_nest_depth: usizeMaximum NEST hierarchy depth (default: 100).
max_block_string_size: usizeMaximum block string size in bytes (default: 10MB).
max_object_keys: usizeMaximum number of keys in a single object/map (default: 10k).
max_total_keys: usizeMaximum total number of keys across all objects (default: 10M).
This prevents DoS attacks where an attacker creates many small objects, each under the max_object_keys limit, but collectively consuming excessive memory. Provides defense-in-depth against memory exhaustion attacks.
Default is 10,000,000 keys, which allows for large documents while still
providing protection against memory exhaustion. For very large datasets,
this can be increased via ParseOptions.
max_total_ids: usizeMaximum total number of IDs across all types (default: 10M).
This prevents DoS attacks where an attacker registers many IDs across multiple types, each type under reasonable limits, but collectively consuming excessive memory in the TypeRegistry indices.
Default is 10,000,000 IDs, matching max_total_keys for consistency. The TypeRegistry maintains two indices (forward and inverted), so each ID registration consumes memory in both data structures.
timeout: Option<Duration>Maximum parsing duration (default: 30 seconds).
Prevents denial-of-service attacks where a malicious document causes the
parser to hang indefinitely. The parser checks elapsed time periodically
and returns a Timeout error if parsing exceeds this duration.
Set to None to disable timeout checking (not recommended for untrusted input).
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Limits
impl RefUnwindSafe for Limits
impl Send for Limits
impl Sync for Limits
impl Unpin for Limits
impl UnwindSafe for Limits
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more