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);| Field | Kind | Default |
|---|---|---|
max_nesting_depth | hard | 256 |
max_stream_decoded | hard | 64 MiB |
max_decoded_total | hard | 1 GiB |
max_filter_chain | hard | 8 |
max_resolve_depth | hard | 32 |
max_page_tree_depth | hard | 256 |
max_tree_depth | hard | 64 |
max_string_length | hard | 16 MiB |
max_xref_sections | soft | 4,096 |
max_object_number | soft | 8,388,607 |
max_warnings | soft | 1,000 |
max_content_operators | hard | 10,000,000 |
max_xobject_depth | hard | 32 |
max_image_pixels | hard (reserved) | 2^28 |
max_read_window | hard | 256 MiB |
max_script_length | soft | 64 KiB |
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
impl Limits
Sourcepub const fn new() -> Self
pub const fn new() -> Self
The defaults from ADR 0003 (the same as Limits::default, usable in const).
Added in 0.2.0.
Sourcepub const fn unlimited() -> Self
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.
Sourcepub const fn max_nesting_depth(&self) -> usize
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.
Sourcepub const fn with_max_nesting_depth(self, value: usize) -> Self
pub const fn with_max_nesting_depth(self, value: usize) -> Self
Sets max_nesting_depth.
Added in 0.2.0.
Sourcepub const fn max_stream_decoded(&self) -> usize
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.
Sourcepub const fn with_max_stream_decoded(self, value: usize) -> Self
pub const fn with_max_stream_decoded(self, value: usize) -> Self
Sets max_stream_decoded.
Added in 0.2.0.
Sourcepub const fn max_decoded_total(&self) -> usize
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.
Sourcepub const fn with_max_decoded_total(self, value: usize) -> Self
pub const fn with_max_decoded_total(self, value: usize) -> Self
Sets max_decoded_total.
Added in 0.2.0.
Sourcepub const fn max_filter_chain(&self) -> usize
pub const fn max_filter_chain(&self) -> usize
Hard: filters in one stream’s /Filter chain (default 8).
Added in 0.2.0.
Sourcepub const fn with_max_filter_chain(self, value: usize) -> Self
pub const fn with_max_filter_chain(self, value: usize) -> Self
Sets max_filter_chain.
Added in 0.2.0.
Sourcepub const fn max_resolve_depth(&self) -> usize
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.
Sourcepub const fn with_max_resolve_depth(self, value: usize) -> Self
pub const fn with_max_resolve_depth(self, value: usize) -> Self
Sets max_resolve_depth.
Added in 0.2.0.
Sourcepub const fn max_page_tree_depth(&self) -> usize
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.
Sourcepub const fn with_max_page_tree_depth(self, value: usize) -> Self
pub const fn with_max_page_tree_depth(self, value: usize) -> Self
Sets max_page_tree_depth.
Added in 0.2.0.
Sourcepub const fn max_tree_depth(&self) -> usize
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.
Sourcepub const fn with_max_tree_depth(self, value: usize) -> Self
pub const fn with_max_tree_depth(self, value: usize) -> Self
Sets max_tree_depth.
Added in 0.2.0.
Sourcepub const fn max_string_length(&self) -> usize
pub const fn max_string_length(&self) -> usize
Hard: bytes in one string or name token (default 16 MiB).
Added in 0.2.0.
Sourcepub const fn with_max_string_length(self, value: usize) -> Self
pub const fn with_max_string_length(self, value: usize) -> Self
Sets max_string_length.
Added in 0.2.0.
Sourcepub const fn max_xref_sections(&self) -> usize
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.
Sourcepub const fn with_max_xref_sections(self, value: usize) -> Self
pub const fn with_max_xref_sections(self, value: usize) -> Self
Sets max_xref_sections.
Added in 0.2.0.
Sourcepub const fn max_object_number(&self) -> u32
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.
Sourcepub const fn with_max_object_number(self, value: u32) -> Self
pub const fn with_max_object_number(self, value: u32) -> Self
Sets max_object_number.
Added in 0.2.0.
Sourcepub const fn max_warnings(&self) -> usize
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.
Sourcepub const fn with_max_warnings(self, value: usize) -> Self
pub const fn with_max_warnings(self, value: usize) -> Self
Sets max_warnings.
Added in 0.2.0.
Sourcepub const fn max_content_operators(&self) -> u64
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.
Sourcepub const fn with_max_content_operators(self, value: u64) -> Self
pub const fn with_max_content_operators(self, value: u64) -> Self
Sets max_content_operators.
Added in 0.2.0.
Sourcepub const fn max_xobject_depth(&self) -> usize
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.
Sourcepub const fn with_max_xobject_depth(self, value: usize) -> Self
pub const fn with_max_xobject_depth(self, value: usize) -> Self
Sets max_xobject_depth.
Added in 0.2.0.
Sourcepub const fn max_image_pixels(&self) -> u64
pub const fn max_image_pixels(&self) -> u64
Hard, reserved: pixels in one decoded image (default 2^28).
Added in 0.2.0.
Sourcepub const fn with_max_image_pixels(self, value: u64) -> Self
pub const fn with_max_image_pixels(self, value: u64) -> Self
Sets max_image_pixels.
Added in 0.2.0.
Sourcepub const fn max_read_window(&self) -> usize
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.
Sourcepub const fn with_max_read_window(self, value: usize) -> Self
pub const fn with_max_read_window(self, value: usize) -> Self
Sets max_read_window.
Added in 0.2.0.
Sourcepub const fn max_script_length(&self) -> usize
pub const fn max_script_length(&self) -> usize
Soft: bytes of one script that form behaviour reads as tokens (a field’s /AA K,
F, V or C JavaScript, ADR 0021 §2; default 64 KiB). A longer script is not
read: it counts as not handled, and the field is filled without its behaviour.
Added in 0.6.0.
Sourcepub const fn with_max_script_length(self, value: usize) -> Self
pub const fn with_max_script_length(self, value: usize) -> Self
Sets max_script_length.
Added in 0.6.0.