lznt1
A safe, pure-Rust, no_std implementation of the LZNT1 compression algorithm.
LZNT1 is the standard compression algorithm used by the Windows NT kernel, notably in NTFS filesystem compression, Active Directory replication, and various Windows API functions (RtlCompressBuffer). This crate allows you to read and write LZNT1 streams on any platform without linking to system libraries.
โจ Features
- Pure Rust: No C dependencies or bindings.
- Safe: Enforced via
#![forbid(unsafe_code)]. no_stdCompatible: only requires thealloccrate.- Robust: Extensively fuzz-tested to ensure resilience against malformed inputs.
- Simple API: Straightforward
compressanddecompressfunctions operating on byte slices and vectors.
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "0.1.0" # Use the latest version
๐ Usage
Decompression
use decompress;
Compression
use compress;
๐ ๏ธ Technical Details
LZNT1 works by splitting data into 4KB chunks. Each chunk is stored either:
- Compressed: A header (
0xB000+ size) followed by LZ77 sequences (literals and offset/length tuples). - Uncompressed: A header (
0x3000+ size) followed by raw data (used when compression doesn't save space).
This implementation handles the adaptive window splitting logic and the "Tag Group" format (1 tag byte per 8 items) defined by the algorithm.
๐งช Testing & Fuzzing
This crate prioritizes correctness and safety.
- Unit Tests: Comprehensive suite covering edge cases, boundary conditions, and RLE patterns.
- Fuzzing: Integration with
cargo-fuzzto verify that the decompressor never panics or crashes, even on malicious/random input. - Benchmarks: Performance tracked via
criterion.
To run the tests:
To run benchmarks:
โ๏ธ License
This project is licensed under the MIT License.