larzarchive
zip/tar with safe extraction. Pure Python, zero dependencies.
Extracting an untrusted archive is a classic vulnerability: a member named
../../etc/cron.d/x or an absolute path escapes the destination ("Zip Slip").
larzarchive refuses those by resolving every member's real path and checking it
stays inside the target - and it skips symlink/device members in tars. A clean
create/extract/list API over the standard library, auto-detecting format.
from larzarchive import create, extract, listing
create("bundle.zip", "myfolder")
create("bundle.tar.gz", ["a.txt", "b.txt"])
extract("bundle.zip", "out/") # raises UnsafeArchive on a malicious member
listing("bundle.zip")
Why
- Safe by default.
extract()validates every member's resolved path against the destination, so path-traversal ("Zip Slip") archives raiseUnsafeArchiveinstead of overwriting files outside the target. It also skips symlink/hardlink/ device entries in tars. (safe=Falseis a documented escape hatch.) - One API, every format. zip, tar, tar.gz, tar.bz2, tar.xz - detected from the
filename.
createtakes a directory, a single file, or a list of paths (or(path, arcname)pairs). - Zero dependencies. A thin, hardened layer over
zipfile/tarfile.
Install
pip install larzarchive
Usage
from larzarchive import create, extract, listing
create("release.tar.gz", "dist") # a directory
create("files.zip", ["a.txt", "b.txt"]) # a list of files
listing("release.tar.gz") # -> member names
paths = extract("release.tar.gz", "unpacked/") # safe; returns extracted paths
Tests
python -m unittest discover -s tests -v # 7 tests incl. zip-slip + tar-slip rejection
The Larz stack
One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.
License
MIT (c) larz-scripter
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file larzarchive-0.1.0.tar.gz.
File metadata
- Download URL: larzarchive-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f79201741badf3a9cb44606065fa5334147f78dbb566979111f4d730166e0e1e
|
|
| MD5 |
89c7e56637394fa7b7743ab7fcbaad49
|
|
| BLAKE2b-256 |
44e12647d9fad037a658027c8baecb0de9b5abaf3a7d811cb52c144e4daac6e4
|
File details
Details for the file larzarchive-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larzarchive-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ace58a815a5b5a1628c0f7ef6016edfff8f413dfc565bb252e20b9aa2c7e05a
|
|
| MD5 |
f7505d6e922741af71882b4d18c228b2
|
|
| BLAKE2b-256 |
4c100410780724fc9ac78f6a9f4536d2f8350497fe7daa72296f8d124c4792f5
|