Skip to main content

PackageLimits

Struct PackageLimits 

Source
pub struct PackageLimits {
    pub max_total_uncompressed: u64,
    pub max_single_uncompressed: u64,
    pub max_compression_ratio: u64,
    pub max_entries: usize,
    pub max_filename_len: usize,
}
Expand description

ZIP archive size and complexity limits to prevent decompression bombs and element explosion attacks.

§Examples

use easydoc_reader::security::PackageLimits;

let limits = PackageLimits::new();
// Default: 100 MB total, 50 MB per entry, 100x ratio, 10 000 entries
assert_eq!(limits.max_total_uncompressed, 100 * 1024 * 1024);

Fields§

§max_total_uncompressed: u64

Maximum total uncompressed size across all entries (bytes). Default: 100 MB.

§max_single_uncompressed: u64

Maximum uncompressed size for a single entry (bytes). Default: 50 MB.

§max_compression_ratio: u64

Maximum allowed compression ratio (uncompressed / compressed). Default: 100.

§max_entries: usize

Maximum number of entries in the archive. Default: 10 000.

§max_filename_len: usize

Maximum length of a single filename (bytes). Default: 256.

Implementations§

Source§

impl PackageLimits

Source

pub fn new() -> Self

Creates limits with the default conservative policy.

Source

pub fn validate_archive<R: Read + Seek>( &self, archive: &mut ZipArchive<R>, ) -> Result<(), String>

Validates a ZIP archive against all configured limits.

Checks:

  1. Entry count does not exceed max_entries.
  2. Each filename is within max_filename_len.
  3. No path traversal (.. or leading /) – Zip Slip prevention.
  4. No single entry exceeds max_single_uncompressed.
  5. Per-entry compression ratio does not exceed max_compression_ratio.
  6. Total uncompressed size does not exceed max_total_uncompressed.
  7. Overall compression ratio does not exceed max_compression_ratio.
§Errors

Returns a human-readable error describing which limit was exceeded.

Trait Implementations§

Source§

impl Clone for PackageLimits

Source§

fn clone(&self) -> PackageLimits

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 Debug for PackageLimits

Source§

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

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

impl Default for PackageLimits

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> 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, <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.