Skip to main content

Limits

Struct Limits 

Source
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: usize

Maximum file size in bytes (default: 1GB).

§max_line_length: usize

Maximum line length in bytes (default: 1MB).

§max_indent_depth: usize

Maximum indent depth (default: 50).

§max_nodes: usize

Maximum number of nodes (default: 10M).

§max_aliases: usize

Maximum number of aliases (default: 10k).

§max_columns: usize

Maximum columns per schema (default: 100).

§max_nest_depth: usize

Maximum NEST hierarchy depth (default: 100).

§max_block_string_size: usize

Maximum block string size in bytes (default: 10MB).

§max_object_keys: usize

Maximum number of keys in a single object/map (default: 10k).

§max_total_keys: usize

Maximum 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: usize

Maximum 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§

Source§

impl Limits

Source

pub fn unlimited() -> Self

Create limits with no restrictions (for testing).

Trait Implementations§

Source§

impl Clone for Limits

Source§

fn clone(&self) -> Limits

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Limits

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Limits

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.