Skip to main content

Limits

Struct Limits 

Source
pub struct Limits {
    pub max_metadata_size: u32,
    pub max_path_len: Option<u32>,
    pub max_pending_entries: usize,
    pub max_sparse_entries: usize,
}
Expand description

Configurable security limits for tar archive parsing.

These limits protect against malicious or malformed archives that could exhaust memory or create excessively long paths.

§Example

use tar_core::parse::Limits;

// Use defaults
let limits = Limits::default();

// Customize limits
let limits = Limits {
    max_metadata_size: 64 * 1024,
    // Set to libc::PATH_MAX when extracting to disk
    max_path_len: Some(4096),
    ..Default::default()
};

Fields§

§max_metadata_size: u32

Maximum total size of all extension metadata for a single entry, in bytes.

This is an aggregate budget: the combined size of PAX extended headers, GNU long name, and GNU long link data for one file entry must not exceed this limit. Exceeding it will cause a ParseError::MetadataTooLarge error.

Default: 1 MiB (1,048,576 bytes).

§max_path_len: Option<u32>

Optional maximum path length in bytes.

When set, paths and link targets exceeding this limit will cause a ParseError::PathTooLong error. When None, no path length check is performed (the default).

Callers extracting to a real filesystem should set this to libc::PATH_MAX (4096 on Linux, 1024 on macOS) or the appropriate platform constant.

Default: None.

§max_pending_entries: usize

Maximum number of consecutive metadata entries before an actual entry.

Prevents infinite loops from malformed archives that contain only metadata entries (GNU long name, PAX headers) without actual file entries. Exceeding this limit will cause a ParseError::TooManyPendingEntries error.

Default: 16 entries.

§max_sparse_entries: usize

Maximum number of sparse data entries (chunks) in a sparse file.

Prevents unbounded memory allocation from a malicious archive that claims an enormous number of sparse regions (see CVE-2025-58183 for a similar issue in Go’s archive/tar).

For old GNU sparse format, each 512-byte extension block holds 21 descriptors, so 1000 entries requires ~48 extension blocks (~24 KiB).

Default: 10000.

Implementations§

Source§

impl Limits

Source

pub fn new() -> Self

Create a new Limits with default values.

Source

pub fn permissive() -> Self

Create permissive limits suitable for trusted archives.

This sets very high limits that effectively disable most checks. Only use this for archives from trusted sources.

Source

pub fn check_path_len(&self, len: usize) -> Result<()>

Check a path length against the configured limit.

Returns Ok(()) if the path is within the limit (or no limit is set), or Err(ParseError::PathTooLong) if it exceeds it.

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

impl PartialEq for Limits

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Limits

Source§

impl StructuralPartialEq for Limits

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