exarch-core
Memory-safe archive extraction library with security validation.
This crate is part of the exarch workspace.
Installation
[]
= "0.1"
[!IMPORTANT] Requires Rust 1.89.0 or later (Edition 2024).
Usage
use ;
Custom Security Configuration
use SecurityConfig;
let config = SecurityConfig ;
Builder Pattern
use ArchiveBuilder;
let mut archive = new
.max_file_size
.max_compression_ratio
.open?;
let report = archive.extract?;
Security Features
exarch-core provides defense-in-depth protection against common archive vulnerabilities:
| Protection | Description | Default |
|---|---|---|
| Path traversal | Blocks ../ and absolute paths |
Enabled |
| Symlink attacks | Prevents symlinks escaping extraction directory | Blocked |
| Hardlink attacks | Validates hardlink targets within extraction directory | Blocked |
| Zip bombs | Detects high compression ratios | Enabled (100x limit) |
| Permission sanitization | Strips setuid/setgid bits | Enabled |
| Size limits | Configurable file and total size limits | 50 MB / 10 GB |
[!CAUTION] Default configuration blocks symlinks and hardlinks. Enable only when you trust the archive source.
Archive Creation
Create archives with secure defaults:
use ;
// Simple creation with defaults
let config = default;
let report = create_archive?;
println!;
Builder Pattern
use ArchiveCreator;
let report = new
.output
.add_source
.add_source
.add_source
.compression_level
.exclude
.exclude
.create?;
CreationConfig Options
| Option | Default | Description |
|---|---|---|
follow_symlinks |
false |
Follow symbolic links |
include_hidden |
false |
Include hidden files (.*) |
compression_level |
6 |
Compression level (1-9) |
exclude_patterns |
[".git", ".DS_Store", "*.tmp"] |
Glob patterns to exclude |
strip_prefix |
None |
Strip prefix from paths |
preserve_permissions |
true |
Preserve Unix permissions |
Supported Formats
| Extension | Format | Compression | Extraction | Creation |
|---|---|---|---|---|
.tar |
TAR | None | Yes | Yes |
.tar.gz, .tgz |
TAR | Gzip | Yes | Yes |
.tar.bz2, .tbz2 |
TAR | Bzip2 | Yes | Yes |
.tar.xz, .txz |
TAR | XZ | Yes | Yes |
.tar.zst, .tzst |
TAR | Zstd | Yes | Yes |
.zip |
ZIP | Deflate | Yes | Yes |
API Overview
Main Types
| Type | Description |
|---|---|
extract_archive |
High-level extraction function |
Archive |
Archive handle with typestate pattern |
ArchiveBuilder |
Builder for configuring extraction |
SecurityConfig |
Security configuration options |
ExtractionReport |
Extraction statistics and results |
ExtractionError |
Error types for extraction failures |
Error Handling
use ;
match extract_archive
Performance
Optimized for throughput with:
- Streaming extraction (no full archive buffering)
- Reusable 64KB copy buffers per archive
- Buffered I/O for file writes
SmallVecfor hardlink tracking (avoids heap allocation for typical archives)- Fast-path quota checks for unlimited quotas
Related Crates
exarch-python— Python bindings via PyO3exarch-node— Node.js bindings via napi-rs
MSRV Policy
[!NOTE] Minimum Supported Rust Version: 1.89.0. MSRV increases are minor version bumps.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.