pub struct Limits {
pub max_archive_size: u64,
pub max_entry_uncompressed_size: u64,
pub max_total_uncompressed_size: u64,
pub max_entries: usize,
pub max_compression_ratio: f64,
}Expand description
Safety guardrails for archive size and expansion limits.
These limits protect against zip bombs, resource exhaustion, and other denial-of-service attacks via malicious archives.
§Examples
use openpack::Limits;
// Use default limits for most use cases
let limits = Limits::default();
assert!(limits.max_archive_size > 0);Fields§
§max_archive_size: u64Maximum size of the archive file itself in bytes.
Default: 256 MiB
max_entry_uncompressed_size: u64Maximum uncompressed size of any single entry in bytes.
Default: 50 MiB
max_total_uncompressed_size: u64Maximum total uncompressed size of all entries combined in bytes.
Default: 128 MiB
max_entries: usizeMaximum number of entries allowed in the archive.
Default: 2048
max_compression_ratio: f64Maximum compression ratio (uncompressed / compressed) allowed. Higher ratios may indicate zip bombs.
Default: 100.0
Implementations§
Source§impl Limits
impl Limits
Sourcepub fn strict() -> Self
pub fn strict() -> Self
Provides very restrictive limits for highly untrusted archives.
§Examples
use openpack::Limits;
let limits = Limits::strict();Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Provides extremely loose limits for trusted archives only.
§Examples
use openpack::Limits;
let limits = Limits::permissive();Sourcepub fn from_toml(raw: &str) -> Result<Self, OpenPackError>
pub fn from_toml(raw: &str) -> Result<Self, OpenPackError>
Parses limits from a TOML string.
§Examples
use openpack::Limits;
let toml_str = r#"
max_archive_size = 104857600
max_entry_uncompressed_size = 10485760
max_total_uncompressed_size = 52428800
max_entries = 1000
max_compression_ratio = 50.0
"#;
let limits = Limits::from_toml(toml_str).unwrap();Sourcepub fn from_toml_file(path: &Path) -> Result<Self, OpenPackError>
pub fn from_toml_file(path: &Path) -> Result<Self, OpenPackError>
Parses limits from a TOML file.