pub struct ProcessingLimits {
pub max_file_bytes: u64,
pub max_stream_bytes: u64,
pub max_total_memory_bytes: u64,
pub max_object_depth: u32,
pub max_operator_count: u64,
pub max_image_pixels: u64,
pub max_xfa_nesting_depth: u32,
pub max_formcalc_depth: u32,
}Expand description
Resource limits for a single PDF processing operation.
Construct via ProcessingLimits::default() for standard limits,
or use the builder methods to customize for your use case.
§Examples
use pdf_engine::limits::ProcessingLimits;
// Default limits (recommended for server-side processing):
let limits = ProcessingLimits::default();
// Stricter limits for WASM/browser context:
let wasm_limits = ProcessingLimits::wasm();
// Custom limits:
let custom = ProcessingLimits::default()
.max_file_bytes(100 * 1024 * 1024) // 100 MB
.max_stream_bytes(64 * 1024 * 1024); // 64 MB per streamFields§
§max_file_bytes: u64Maximum PDF file size in bytes. Default: 500 MB.
max_stream_bytes: u64Maximum decompressed size of any single stream. Default: 256 MB. Prevents zip bombs via FlateDecode or LZWDecode.
max_total_memory_bytes: u64Maximum total memory allocated per document. Default: 1 GB.
max_object_depth: u32Maximum object reference depth (prevents stack overflow on recursive refs). Default: 100.
max_operator_count: u64Maximum content stream operators per page. Default: 10,000,000.
max_image_pixels: u64Maximum pixel count per image (width × height). Default: 268,435,456 (16384²).
max_xfa_nesting_depth: u32Maximum XFA template XML nesting depth. Default: 50.
max_formcalc_depth: u32Maximum FormCalc recursion depth. Default: 200.
Implementations§
Source§impl ProcessingLimits
impl ProcessingLimits
Sourcepub fn wasm() -> Self
pub fn wasm() -> Self
Strict limits for WASM/browser contexts with limited memory.
- Max file: 50 MB
- Max stream: 32 MB
- Max total memory: 128 MB
- Image pixels: 64 MP (8192×8192)
Sourcepub fn max_file_bytes(self, bytes: u64) -> Self
pub fn max_file_bytes(self, bytes: u64) -> Self
Set maximum PDF file size.
Sourcepub fn max_stream_bytes(self, bytes: u64) -> Self
pub fn max_stream_bytes(self, bytes: u64) -> Self
Set maximum decompressed stream size.
Sourcepub fn max_total_memory_bytes(self, bytes: u64) -> Self
pub fn max_total_memory_bytes(self, bytes: u64) -> Self
Set maximum total memory per document.
Sourcepub fn max_object_depth(self, depth: u32) -> Self
pub fn max_object_depth(self, depth: u32) -> Self
Set maximum object reference depth.
Sourcepub fn max_operator_count(self, count: u64) -> Self
pub fn max_operator_count(self, count: u64) -> Self
Set maximum content stream operator count.
Sourcepub fn max_image_pixels(self, pixels: u64) -> Self
pub fn max_image_pixels(self, pixels: u64) -> Self
Set maximum image pixel count (width × height).
Sourcepub fn max_xfa_nesting_depth(self, depth: u32) -> Self
pub fn max_xfa_nesting_depth(self, depth: u32) -> Self
Set maximum XFA template nesting depth.
Sourcepub fn max_formcalc_depth(self, depth: u32) -> Self
pub fn max_formcalc_depth(self, depth: u32) -> Self
Set maximum FormCalc recursion depth.
Sourcepub fn check_file_size(&self, bytes: u64) -> Result<(), LimitError>
pub fn check_file_size(&self, bytes: u64) -> Result<(), LimitError>
Check if a file size is within limits. Returns Err with a descriptive message if exceeded.
Sourcepub fn check_stream_size(&self, bytes: u64) -> Result<(), LimitError>
pub fn check_stream_size(&self, bytes: u64) -> Result<(), LimitError>
Check if a decompressed stream size is within limits.
Sourcepub fn check_image_pixels(
&self,
width: u64,
height: u64,
) -> Result<(), LimitError>
pub fn check_image_pixels( &self, width: u64, height: u64, ) -> Result<(), LimitError>
Check if image dimensions are within limits.
Sourcepub fn check_object_depth(&self, depth: u32) -> Result<(), LimitError>
pub fn check_object_depth(&self, depth: u32) -> Result<(), LimitError>
Check if an object depth is within limits.
Trait Implementations§
Source§impl Clone for ProcessingLimits
impl Clone for ProcessingLimits
Source§fn clone(&self) -> ProcessingLimits
fn clone(&self) -> ProcessingLimits
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProcessingLimits
impl Debug for ProcessingLimits
Auto Trait Implementations§
impl Freeze for ProcessingLimits
impl RefUnwindSafe for ProcessingLimits
impl Send for ProcessingLimits
impl Sync for ProcessingLimits
impl Unpin for ProcessingLimits
impl UnsafeUnpin for ProcessingLimits
impl UnwindSafe for ProcessingLimits
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().