Expand description
Memory-safe archive extraction library with security validation.
exarch-core provides a safe API for extracting archive files (tar, zip)
with built-in protection against common security vulnerabilities like
path traversal, zip bombs, symlink attacks, and hardlink attacks.
§Examples
use exarch_core::SecurityConfig;
use exarch_core::extract_archive;
let config = SecurityConfig::default();
let report = extract_archive("archive.tar.gz", "/output/dir", &config)?;
println!("Extracted {} files", report.files_extracted);Macros§
- non_
zero - Builds a
NonZerovalue from a constant, failing the build when the constant is zero. - ratio_
limit - Builds a
RatioLimitfrom a constant, failing the build when it is not finite and positive.
Structs§
- Admitted
Size - The size of a file the pipeline admitted: the bytes a
QuotaPermitreserved for it. - Allowed
Features - Feature flags controlling what archive features are allowed during extraction.
- Archive
Entry - Single entry in archive manifest.
- Archive
Manifest - Complete manifest of archive contents.
- Archive
Reader - An archive supplied as a reader.
- Archive
Writer - An archive destination supplied as a writer.
- Boundary
Path - Validates a raw, caller-supplied path string before it enters the
archive pipeline. Shared by
exarch-pythonandexarch-node. A caller-supplied path string that passed the boundary checks. - Callback
Sink - An
EntrySinkthat delivers each entry to a closure as it is verified. - Central
Record Ordinal - Position of a record in the raw central directory, counting records
that the
zipcrate collapsed because they share a name. - Checked
Link Target - The target of a symlink that passed validation, borrowed from its
SafeSymlink. - Compressed
- A byte count as stored in the archive.
- Compression
Level - A compression level on exarch’s 1-9 scale; the default is 6.
- Create
Request - Creates an archive from files and directories.
- Creation
Config - Configuration for archive creation operations.
- Creation
Report - Report of an archive creation operation.
- Decompression
Budget - Upper bound on the bytes
verifydecodes to check payload integrity. - DestDir
- A validated destination directory for archive extraction.
- Entry
Count - Proof that one entry was counted against
max_file_countwhile its bytes are not yet charged. - Entry
Pattern - A glob pattern that selects archive entries, built once when the pattern is set.
- Entry
Position - Where an entry sits in the operation: its 1-based number and the total.
- Entry
Selection - The entries of an archive an extraction takes, and how their paths are rewritten.
- Entry
Size - The declared sizes of one entry, as the validators consume them.
- Extension
- A file extension without its leading dot, ASCII-lowercased.
- Extensions
- A non-empty list of allowed
Extensions. - Extract
Request - Extracts an archive into a directory.
- Extraction
Options - Options controlling extraction behavior (non-security).
- Extraction
Report - Report of an archive extraction operation.
- FfiError
Message - Error data for FFI consumption.
- FfiName
Collision - Two entry names the host filesystem treats as one, redacted for a binding.
- FfiSource
Fault - What a binding needs of an unreadable creation source, redacted like the rest of the message.
- Hardlink
Target - A hardlink target that passed
HardlinkTrackervalidation. - Integrity
Gaps - What a requested integrity check left unverified.
- IoContext
- Pairs a static, non-path-bearing summary with the dynamic detail of an
I/O failure constructed via
std::io::Error::other. - Landing
- A path extraction creates, with what put it there.
- Landing
Path - The destination-relative path an entry lands at, derived lexically.
- List
Options - Options controlling
listbehavior. - List
Request - Lists the contents of an archive without extracting it.
- Listed
Archive - An archive that was listed and is ready to extract without decoding it again where that is possible.
- Listed
Extract Options - The options of
ListedArchive::extract: the knobs that may still vary after the archive was listed. - Memory
Extract Request - How
extract_reader_to_memoryvalidates and stores an archive. - Memory
File - The writer of a file being stored by a
MemorySink. - Memory
Limit - The most bytes a
MemorySinkaccepts, counted as its payload (file data, hardlink copies, symlink targets) plus, for every entry, the bytes of its path andMemorySink::ENTRY_OVERHEAD. - Memory
Sink - An
EntrySinkthat keeps the extracted tree in memory. - Noop
Progress - No-op implementation of
ProgressCallbackthat does nothing. - Output
File - The archive file a creation writes: its path, whether it may replace an existing file and how its format is chosen.
- Oversized
Entry - An entry whose path exceeds the host’s name limits.
- Partial
- An extraction that stopped after recording progress, or that left its staging directory behind.
- Path
Component Name - One normal path component that archive entries may not contain.
- Quota
Permit - Proof that a file’s size was successfully reserved against a
QuotaTracker. - Ratio
Limit - A compression ratio limit: finite and greater than zero.
- RawMode
- A Unix permission mode exactly as an archive header records it.
- Replace
Failure - Why replacing an existing destination failed, and what is left behind.
- Reuse
Limit - The most decoded bytes a ZIP extraction keeps for reuse.
- Safe
Path - A validated path that is safe for extraction.
- Safe
Symlink - A validated symlink that is safe for extraction.
- Sanitized
Mode - A Unix permission mode that has already passed through
sanitize_permissions. - Security
Config - Security configuration with default-deny settings.
- Sink
Extract Request - Extracts an archive read from a reader into an
EntrySink. - Sink
Full - The payload of the
io::ErrorKind::QuotaExceedederror a sink returns when it has no room for an entry. - Sink
Options - What a sink extraction honours of
ExtractionOptions. - Skip
- One entry left out of an operation, with the reason.
- Skips
- Everything an operation left out: exact counts per
SkipKindplus a bounded sample of the individual entries. - Solid
Block - Compressed and uncompressed totals of one solid block.
- Solid
Limits - Limits applied to a solid 7z archive that is admitted.
- Staging
Leftover - A staging directory that a failed replace left on disk.
- Staging
Place - Where the staging entries of one output live, and the path a backup is renamed back to.
- Strip
Components - How many leading path components extraction drops from every entry.
- Unclassified
- A malformed-archive refusal that has no family of its own.
- Uncompressed
- A byte count after decoding.
- Unix
Time - A point in time as an offset from the Unix epoch, which may be negative.
- Unverified
Entry - One entry the integrity check could not verify, and why.
- Verification
Issue - Single verification issue.
- Verification
Options - Options controlling
verifybehavior. - Verification
Report - Result of archive verification.
- Verify
Request - Verifies an archive’s security without extracting it.
- ZipBomb
Details - Sizes and scope of a rejected compression ratio.
- ZipEntry
Index - Index of an entry in the
zipcrate’s entry map, which equals its position in the manifest listing.
Enums§
- Admit
- Whether an archive feature is admitted.
- Archive
Error - Errors that can occur during archive operations (extraction, creation, listing, verification).
- Archive
Type - Supported archive formats.
- Backup
Identity - Whether the identity of a leftover backup was confirmed before its removal failed.
- Callback
Entry - An entry delivered by a
CallbackSink. - Callback
Error - Why
extract_reader_to_callbackfailed. - Check
Status - Status of a specific check category.
- Compression
Codec - Compression codec for archive files.
- Compression
Ratio - Compression ratio of a checked size pair.
- Config
Problem - Why a configuration value or input was refused.
- Config
Setting - A configuration value or required input that was refused.
- Creatable
Format - Archive formats exarch can create.
- Creation
Warning - A condition of a creation worth surfacing that is not a skipped entry.
- Creation
Warning Kind - The class of a
CreationWarning, without its payload. - Decode
Reuse - Where a ZIP extraction keeps decoded output between the structural check and the write, so a deflate entry is decoded once.
- Decode
Reuse Kind - The mode of a
DecodeReusewithout its limit, as the front ends spell it. - Destination
Check - What
ListedArchive::check_destinationrequires of the paths the extraction would write. - Destination
State - Whether a destination is fresh: nothing exists at its final name and the directory that would hold it exists.
- Destination
Step - The step of reaching a destination that failed.
- Disposition
- What extraction does with a listed entry.
- Disposition
Kind - Which way a
Dispositionwent, without its payload. - Durability
- Whether a created archive is flushed to stable storage before it is reported as written.
- EndRecord
Kind - Kind of end record found before an entry.
- Entry
Compression - How an archive entry’s data is compressed.
- Entry
Total - How many entries an operation has, when it knows.
- Error
Code - Stable machine-readable identifier of an
ArchiveErrorvariant. - Existing
Files - What extraction does with a destination path that is already occupied.
- Extension
Filter - Which file extensions extraction admits.
- Extract
Only Format - Archive formats exarch can read but not create.
- Extraction
Warning - A condition of an extraction worth surfacing that is not a skipped entry.
- Extraction
Warning Kind - The class of an
ExtractionWarning, without its payload. - FfiDetail
- Structured data behind an
FfiErrorMessage, one variant per error that carries some. - FfiKind
- The error class of an
FfiErrorMessage, with the payload that class carries. - FfiRestore
- What became of the original destination after a failed replace, redacted for a binding.
- Finding
- What a
VerificationIssuefound. - Heuristic
- An observation
verifyreports on its own, not as a refusal. - Hidden
Region - Part of a ZIP file in which an unmapped local header was found.
- Integrity
Check - Whether
verifychecks payload integrity. - Integrity
Status - Result of the payload integrity check.
- Invalid
Archive SubCode - Finer classification of an
ErrorCode::InvalidArchiveerror. - IoKind
- The kind of an I/O failure, spelled the same in every front end.
- Issue
Category - Issue categories (maps to security checks).
- Issue
Severity - Issue severity levels (ordered from least to most severe for Ord).
- Kind
Source - Where a claim about a 7z entry’s kind was recorded.
- Landing
Kind - What put a path in the landing set.
- Limit
- A positive bound, or no bound.
- Link
Kind - The kind of link a target belongs to; the host limits them differently.
- Link
Target - Link target of a manifest entry, as far as the listing could keep it.
- Link
Target State - What a
LinkTargetholds, without the target itself. - Malformation
- Why an archive, or one of its entries, is malformed.
- Manifest
Entry Kind - Kind of a manifest entry; link kinds carry their target.
- Manifest
Entry Type - Entry type in manifest (does NOT require validation).
- Mark
Outcome - What mark propagation did during one extraction.
- Mark
Propagation - Whether extraction copies the archive file’s download-origin mark onto the files it creates.
- Mark
State - The kind of a
MarkOutcome, without its counts. - Memory
Entry - An entry held by a
MemorySink. - Memory
Entry Kind - What a
MemoryEntryor aCallbackEntryholds. - Name
Collision Kind - How two colliding names differ, which sets how serious the collision is.
- Narrowing
Reason - Why the root of an atomic publication gives less access than the destination it replaces or fills.
- Native
Kind - What a 7z header itself says an entry is: a directory has no stream and is not flagged as an empty file.
- Occupied
By - Who made the entry that occupies a path a run was about to write.
- Output
Format - How the archive format of an
OutputFileis chosen. - Output
Policy - Whether creating an output file may replace one that already exists.
- Parallel
Decode - How much extra memory a 7z block may use to decode LZMA2 runs ahead on worker threads.
- Partial
Outcome - What happened to the output of an extraction that stopped part-way.
- Partial
Writes - Fate of the files recorded in a
ArchiveError::PartialExtractionreport. - Path
Model - The path semantics an
EntrySinkis validated against. - Path
Occupant - What already occupies a path an insert collided with.
- Path
Rewrite - How a validated archive path becomes the path an entry lands at.
- Pattern
Refusal - Why a glob entry pattern is refused.
- Permission
Policy - Whether file modes from the archive (or the source tree) are kept.
- Policy
Setting - The
SecurityConfigsetting whose current value refused an entry. - Portable
Hazard - Why a path component is hazardous on some supported platform but not necessarily on the host.
- Protected
Path - What makes a destination too important to replace as a whole.
- Quota
Kind - Payload-free discriminant of a
QuotaResource. - Quota
Resource - Represents a specific quota resource that was exceeded.
- Reader
Format Error - Why the format of an archive supplied as a reader could not be used.
- Requested
Level - A compression level exactly as the caller asked for it.
- Restore
- What became of the original destination after a failed replace.
- Restore
Kind - The outcome of
Restorewithout its payload. - Security
Violation SubCode - Finer classification of an
ErrorCode::SecurityViolationerror. - Seekable
Format - A format that is read through a directory at the end of the archive, and so needs a seekable source.
- SevenZ
Header Table - A table of a 7z header whose declared length is bounded before the header is parsed.
- Skip
Kind - Why an entry was left out of an extraction or creation.
- Solid
Archives - Whether solid 7z archives are extracted, and under which limits.
- Solid
Memory Scope - What a refused solid decoded size was summed over.
- Special
File - A Unix file type that exarch never creates.
- Staged
Output Kind - What a staged output is, which fixes how its destination is resolved.
- Staging
- How extraction stages its output before it is visible at the destination.
- Stored
Targets - Whether listing reads the symlink targets a format keeps in compressed entry data.
- SubCode
- The finer classification of an error, tagged with the class it refines.
- TarAmbiguity
- A TAR header or extension-header construct that readers such as
bsdtarand Pythontarfileresolve differently from thetarcrate. - TarExtension
Kind - An extension header whose body the
tarcrate merges into the next entry. - TarHeader
Field - A numeric header field that must be plain.
- TarNon
Regular Kind - A TAR entry type that has no data and must not declare a payload.
- TarPath
Key - The path-like PAX key that a GNU long record duplicates.
- TarTrailer
Refusal - Why the bytes after the end-of-archive marker of a compressed TAR were refused.
- Trailer
Corruption - What is wrong with the compressed stream after the TAR end-of-archive marker.
- Unverified
Reason - Why part of the payload was not verified by the integrity check.
- Verification
Status - Overall verification status.
- Violation
- Why an operation was denied by security policy.
- Volume
Identity - How the destination volume tells two landings apart, which decides which repeated names extraction skips as duplicates.
- ZipBomb
Scope - What a zip bomb size check was measured over.
- ZipConsistency
Policy - How ZIP structure that different readers interpret differently is handled.
- ZipHeader
Field - Header field in which a ZIP local header disagrees with its central directory record.
- ZipInconsistency
- A structural finding that makes a ZIP archive ambiguous between readers.
- ZipNon
Regular Kind - Kind of entry that is not a regular file but declares a payload.
- ZipStream
Undecided - Why the end of an entry’s compressed stream could not be established.
- ZipUncomparable
- Why a ZIP local header could not be compared with its central directory record.
Constants§
- BACKUP_
PREFIX - The name prefix of the backup an atomic replace renames the previous
destination to; it extends
STAGING_PREFIX. - MAX_
CONFIG_ ENTRY_ LENGTH - Maximum length, in bytes, of a single
SecurityConfigentry — an allowed extension or a banned path component. Shared byexarch-pythonandexarch-node. Maximum length, in bytes, of a singleSecurityConfigentry — an allowed extension or a banned path component. - MAX_
PATH_ LENGTH - Maximum length, in bytes, of a raw path string accepted at the FFI
boundary. Shared by
exarch-pythonandexarch-node. Maximum length, in bytes, of a raw path string accepted at the FFI boundary. - STAGING_
PREFIX - The name prefix of every staging entry (a staging directory, or the temporary file of a staged archive) created next to a destination.
Traits§
- Closed
Enum - An enum with a fixed set of variants and a stable string form for each.
- Entry
Sink - Receives the validated entries of an archive in extraction order.
- Progress
Callback - Callback trait for progress reporting during archive operations.
Functions§
- bytes_
text - Renders raw bytes of an archive name as text, by the rules of
path_text. - create_
archive - Creates an archive from source files and directories.
- detect_
format - Detects the archive type from a file path using two-phase detection.
- extract_
archive - Extracts an archive to the specified output directory.
- extract_
reader_ to_ callback - Extracts the archive in
reader, handing every verified entry toon_entry. - extract_
reader_ to_ memory - Extracts the archive in
readerinto aMemorySink. - format_
entry_ path_ for_ error - Formats an archive-relative, attacker-authored path for an FFI error
message without redaction. Shared by
exarch-pythonandexarch-node. Formats an archive-relative, attacker-authored path for inclusion in an FFI error message. - list_
archive - Lists archive contents without extracting.
- non_
zero_ u64 - Parses a runtime byte count, refusing zero.
- non_
zero_ usize - Parses a runtime count, refusing zero.
- path_
text - Renders a path as text so that two distinct paths never render alike.
- positive_
from_ f64 - Parses a floating-point number from a binding (a JavaScript number) into a positive whole count of at most 2^53 - 1.
- positive_
from_ i128 - Parses a signed integer from a binding, refusing zero, negative values and
values above
u64::MAX. - sanitize_
io_ error_ for_ error - Sanitizes a
std::io::Errormessage for an FFI error message. Shared byexarch-pythonandexarch-node. Sanitizes I/O error messages for FFI error reporting. - sanitize_
path_ for_ error - Redacts a host-derived filesystem path for an FFI error message in
release builds. Shared by
exarch-pythonandexarch-node. Formats a host-derived filesystem path for inclusion in an FFI error message. - staging_
place - Resolves where the staging entries of
outputare created, by the rule the staging code ofkinduses. - utf8_
entry_ path - The text of an archive entry path, or the refusal a front end must raise.
- verify_
archive - Verifies archive security without extracting.
Type Aliases§
- Result
- Result type alias using
ArchiveError.