Skip to main content

Limits

Struct Limits 

Source
pub struct Limits { /* private fields */ }
Expand description

Resource limits for reading untrusted PDF input (ADR 0003 §3).

Copy, with private fields: read a limit with its getter and change it with the matching with_* builder, starting from Limits::default (or Limits::new in a const context):

use laminapdf_syntax::Limits;

const STRICTER: Limits = Limits::new().with_max_nesting_depth(64).with_max_stream_decoded(1 << 20);
assert_eq!(STRICTER.max_nesting_depth(), 64);
assert_eq!(Limits::default().max_nesting_depth(), 256);
FieldKindDefault
max_nesting_depthhard256
max_stream_decodedhard64 MiB
max_decoded_totalhard1 GiB
max_filter_chainhard8
max_resolve_depthhard32
max_page_tree_depthhard256
max_tree_depthhard64
max_string_lengthhard16 MiB
max_xref_sectionssoft4,096
max_object_numbersoft8,388,607
max_warningssoft1,000
max_content_operatorshard10,000,000
max_xobject_depthhard32
max_image_pixelshard (reserved)2^28
max_read_windowhard256 MiB

Reserved limits are part of the API now so they can be configured once, but nothing enforces them until the feature they bound lands (image decoding).

Added in 0.2.0.

Implementations§

Source§

impl Limits

Source

pub const fn new() -> Self

The defaults from ADR 0003 (the same as Limits::default, usable in const).

Added in 0.2.0.

Source

pub const fn unlimited() -> Self

No limits at all, for trusted input only (Lamina PDF’s own output in tests).

Nesting is parsed recursively, so hostile input with unlimited nesting depth can exhaust the stack: never use this for files from outside.

Added in 0.2.0.

Source

pub const fn max_nesting_depth(&self) -> usize

Hard: array/dictionary nesting depth accepted by the parser, and the graphics states one content stream may save with q in laminapdf-content (default 256; ADR 0023 §4).

Added in 0.2.0.

Source

pub const fn with_max_nesting_depth(self, value: usize) -> Self

Sets max_nesting_depth.

Added in 0.2.0.

Source

pub const fn max_stream_decoded(&self) -> usize

Hard: bytes one stream may decode to, per filter stage (default 64 MiB).

Added in 0.2.0.

Source

pub const fn with_max_stream_decoded(self, value: usize) -> Self

Sets max_stream_decoded.

Added in 0.2.0.

Source

pub const fn max_decoded_total(&self) -> usize

Hard: bytes decoded by one top-level call (open, one page’s content, one resolve or decode_stream), across all streams and filter stages (default 1 GiB).

Added in 0.2.0.

Source

pub const fn with_max_decoded_total(self, value: usize) -> Self

Sets max_decoded_total.

Added in 0.2.0.

Source

pub const fn max_filter_chain(&self) -> usize

Hard: filters in one stream’s /Filter chain (default 8).

Added in 0.2.0.

Source

pub const fn with_max_filter_chain(self, value: usize) -> Self

Sets max_filter_chain.

Added in 0.2.0.

Source

pub const fn max_resolve_depth(&self) -> usize

Hard: indirect objects in flight at once while resolving a reference chain (default 32).

Added in 0.2.0.

Source

pub const fn with_max_resolve_depth(self, value: usize) -> Self

Sets max_resolve_depth.

Added in 0.2.0.

Source

pub const fn max_page_tree_depth(&self) -> usize

Hard: /Kids levels below the page-tree root (default 256). Hit inside the tolerant page walk, the subtree is skipped with a page-tree-node-skipped warning, as ADR 0003 §3 prescribes for hard limits on tolerant paths.

Added in 0.2.0.

Source

pub const fn with_max_page_tree_depth(self, value: usize) -> Self

Sets max_page_tree_depth.

Added in 0.2.0.

Source

pub const fn max_tree_depth(&self) -> usize

Hard: depth of name trees, number trees and outlines (default 64; enforced by the typed views).

Added in 0.2.0.

Source

pub const fn with_max_tree_depth(self, value: usize) -> Self

Sets max_tree_depth.

Added in 0.2.0.

Source

pub const fn max_string_length(&self) -> usize

Hard: bytes in one string or name token (default 16 MiB).

Added in 0.2.0.

Source

pub const fn with_max_string_length(self, value: usize) -> Self

Sets max_string_length.

Added in 0.2.0.

Source

pub const fn max_xref_sections(&self) -> usize

Soft: /Prev hops in the xref chain; past it the stored xref is abandoned and rebuilt by scanning (default 4,096).

Added in 0.2.0.

Source

pub const fn with_max_xref_sections(self, value: usize) -> Self

Sets max_xref_sections.

Added in 0.2.0.

Source

pub const fn max_object_number(&self) -> u32

Soft: highest object number kept; higher entries are dropped with a warning (default 8,388,607, ISO 32000-1 Annex C).

Added in 0.2.0.

Source

pub const fn with_max_object_number(self, value: u32) -> Self

Sets max_object_number.

Added in 0.2.0.

Source

pub const fn max_warnings(&self) -> usize

Soft: warnings kept per document; later ones are dropped after one warnings-truncated warning (default 1,000).

Added in 0.2.0.

Source

pub const fn with_max_warnings(self, value: usize) -> Self

Sets max_warnings.

Added in 0.2.0.

Source

pub const fn max_content_operators(&self) -> u64

Hard: operators read by one content-stream interpretation (laminapdf-content), the page’s and every Form XObject’s each time it is drawn (default 10,000,000; ADR 0023).

Added in 0.2.0.

Source

pub const fn with_max_content_operators(self, value: u64) -> Self

Sets max_content_operators.

Added in 0.2.0.

Source

pub const fn max_xobject_depth(&self) -> usize

Hard: Form XObjects drawn at once by laminapdf-content; patterns and Type 3 glyphs too once they are interpreted (default 32; ADR 0023).

Added in 0.2.0.

Source

pub const fn with_max_xobject_depth(self, value: usize) -> Self

Sets max_xobject_depth.

Added in 0.2.0.

Source

pub const fn max_image_pixels(&self) -> u64

Hard, reserved: pixels in one decoded image (default 2^28).

Added in 0.2.0.

Source

pub const fn with_max_image_pixels(self, value: u64) -> Self

Sets max_image_pixels.

Added in 0.2.0.

Source

pub const fn max_read_window(&self) -> usize

Hard: bytes one parse may read from a source without an in-memory slice (laminapdf-cos reads such sources in windows; default 256 MiB). It bounds how far a window grows for one object (its head, a stream’s data, the search for a missing endstream) and the backward walk over an object header found by repair. Past it, the object fails with LimitExceeded where an in-memory parse would have read on; a tolerant path (repair, /Length recovery, the xref entry check) treats the item as unreadable instead. In-memory input is never limited by it.

Added in 0.2.0.

Source

pub const fn with_max_read_window(self, value: usize) -> Self

Sets max_read_window.

Added in 0.2.0.

Trait Implementations§

Source§

impl Clone for Limits

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Limits

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

impl Eq for Limits

Source§

impl Hash for Limits

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Limits

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Limits

Auto Trait Implementations§

§

impl Forget for Limits

§

impl Freeze for Limits

§

impl Move for Limits

§

impl RefUnwindSafe for Limits

§

impl Send for Limits

§

impl Sync for Limits

§

impl Unpin for Limits

§

impl UnsafeUnpin 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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.