Guides
Extract safely
Unpack an archive you do not trust: where the files go, what happens when a name is taken, how to pass a password, and the checks that run whatever you choose.
The default is the safe choice
A plain extract needs no options. peel demo.zip is the
same as peel extract demo.zip, and x and
e are aliases. Rind writes the result in the folder that
holds the archive, renames a file whose name is taken, and adds an
enclosing folder only when the archive needs one. Every check in the safety section below applies, and the CLI has no
flag to turn one off.
peel extract demo.zip -o out -j{
"format": "zip",
"destination": "out",
"extracted": ["out/project", "out/project/docs", "out/project/README.md"],
"skipped": [],
"sources": ["demo.zip"]
}extracted lists every path written, folders included.
skipped lists what was left alone: files kept under
-s and links that lead out of the destination.
sources is every file the archive was read from, such as
each volume of a multipart RAR. The library returns the same data as
ExtractResult, and the C library returns the same JSON. A
failure leaves the destination as it was and arrives as a stable error kind: exit 13 for an unsafe
name, 3 or 4 for a password, 5 for damage.
Destination and enclosing folder
-o DIR sets the destination. Without it, Rind uses the
folder that contains the archive, never a temporary folder.
An archive whose entries are all inside one top-level folder, like
demo.zip with its project/, extracts as that
folder. An archive with several top-level items would spill them into
your destination, so Rind wraps them in a folder named after the archive
with -peeled added. Two flags override that:
-dalways wraps, even a single-folder archive:demo.zipgivesdemo-peeled/project.-Dnever wraps. The archive’s own top-level items land directly in the destination.
In Rust that is EnclosingDirectory::WhenNeeded,
Always or Never, and in C the
enclosing argument is 0, 1 or 2.
use peel_core::{peel, Collision, EnclosingDirectory, ExtractPolicy};
use std::path::Path;
let policy = ExtractPolicy {
destination: Some("out".into()), // default: beside the archive
collision: Collision::Rename, // Error | Overwrite | Rename | Skip
enclosing_directory: EnclosingDirectory::WhenNeeded, // | Always | Never
..ExtractPolicy::default()
};
let result = peel(Path::new("demo.zip"), &policy)?; // ExtractResult
println!("{} paths in {}", result.extracted.len(), result.destination.display());/* collision: 0 error, 1 overwrite, 2 rename, 3 skip. enclosing: 0 when needed, 1 always, 2 never. */
char *r = peel_extract_to("demo.zip", "out", 2, 0);When a name is taken
Extracting into a folder that already holds files merges into it. Rind never replaces a file unless you ask.
| Flag | Policy | Result |
|---|---|---|
-r, --force-rename |
Rename (default) | The new file gets a number: README-1.md, then
README-2.md |
-s, --force-skip |
Skip | The existing file stays, and the new one is listed under
skipped |
-f, --force-overwrite |
Overwrite | The new file replaces the old one |
peel x flat.zip -o merged -D -q
$ peel x flat.zip -o merged -D
zip → merged (2 files)
merged/README-1.md
merged/main-1.rs
$ peel x flat.zip -o merged -D -s
zip → merged (0 files)
skipped:
merged/README.md
merged/main.rs
$ ls merged
README-1.md
README.md
main-1.rs
main.rspeel 1.4.0, recorded 2026-11-26.The library and the C library have a fourth policy the CLI does not:
Collision::Error, or 0 in C. It fails with
already_exists and writes nothing. Use it when a name clash
means something is wrong.
--delete removes the source archive after a successful
extract and never after a failed one.
Choose what to extract
Name members after the archive and only those are written. Each argument is an exact path, a folder, or a pattern:
- A path such as
project/README.mdselects that entry. - A folder such as
project/docsselects everything under it. - A bare name such as
README.mdselects any entry with that file name, in any folder. - A
*pattern matches across folders, so*.mdselects every Markdown file.*is the only wildcard:?is an ordinary character.
peel x demo.zip -o docs-only 'project/docs/*.md'
zip → docs-only (6 files)
docs-only/project/docs/chapter-1.md
docs-only/project/docs/chapter-2.md
docs-only/project/docs/chapter-3.md
docs-only/project/docs/chapter-4.md
docs-only/project/docs/chapter-5.md
docs-only/project/docs/chapter-6.mdpeel 1.4.0, recorded 2026-11-26.extracted empty.
If a script depends on a member being there, check the list first with
peel list, or read it directly with peel cat,
which needs the exact name and fails with not_found.
In Rust, set
selection: Some(vec!["project/docs/*.md".into()]). The C
library has no selection argument on peel_extract; to write
one member, call peel_extract_entry with its exact
name.
/* One entry by its exact listed name, at most 1 MiB. Returns {"path":...,"size":...}. */
char *r = peel_extract_entry("demo.zip", "project/README.md", "out", 1u << 20);Passwords
Pass a password on a pipe, most private first:
--password-stdinreads it from standard input. One trailing newline is dropped.--password-fd Nreads it from a file descriptor your process inherited.PEEL_PASSWORDworks for scripts, but any process of the same user can read it whilepeelruns (ps ewwshows it).peelremoves the variable from its own environment at start, so nothing it launches inherits it.-por--passwordputs the password on the command line, wherepsshows it to every user.
A pipe or -p beats PEEL_PASSWORD when both
are set, and --password-stdin cannot be combined with
-p (a usage error, exit 2). A pipe is invisible to other
processes, which is why the Mac app uses one.
security find-generic-password -s backup -w | peel x locked.zip -o out --password-stdinprintf 'wrong' | peel x locked.zip -o unlocked --password-stdin -j; echo "exit $?"
{"error":"wrong_password","detail":"extract locked.zip: incorrect password"}
exit 4
$ printf 'correct horse battery staple' | peel x locked.zip -o unlocked --password-stdin -q; echo "exit $?"
exit 0
$ ls unlocked
projectpeel 1.4.0, recorded 2026-11-26.A missing password is password_required (exit 3) and a
wrong one is wrong_password (exit 4), so a script can ask
again. Neither leaves a folder behind. One password opens one archive:
RAR and 7z take a single password for the whole archive. The demo
password above is public.
In Rust, a password is a Secret, which wipes its memory
when dropped.
use peel_core::{ExtractPolicy, Secret};
let policy = ExtractPolicy {
password: Some(Secret::from("correct horse battery staple")),
..ExtractPolicy::default()
};In C, use peel_extract_with_password,
peel_extract_entry_with_password or
peel_session_open with a password. They copy it once, wipe
their copy before returning and never read the environment. NULL or an
empty string means none. The older peel_extract,
peel_extract_to, peel_extract_member and
peel_extract_entry still read PEEL_PASSWORD,
so avoid them for encrypted archives. Wipe your own copy as well.
Archives inside archives
By default an archive inside the archive is extracted as a file and
left packed. --deep keeps unpacking whatever it finds, and
stops at 16 levels. Each level gets its own resource budget. The JSON
result lists only the outer archive’s paths, so read the folder if you
need the inner ones.
peel x bundle.zip -o out --deepWatch progress
--ndjson-progress writes one JSON object per line to
standard error, at most about ten a second:
peel x demo.zip -o watched -q --ndjson-progress
{"phase":"extract","entries_done":0,"entries_total":11,"bytes_done":0,"bytes_total":null,"current_entry":null,"destination":"watched"}
{"phase":"extract","entries_done":11,"entries_total":11,"bytes_done":32550,"bytes_total":32550,"current_entry":null}
{"phase":"extract","entries_done":11,"entries_total":11,"bytes_done":32550,"bytes_total":32550,"current_entry":null}
{"phase":"done","entries_done":11,"entries_total":11,"bytes_done":0,"bytes_total":null,"current_entry":null}peel 1.4.0, recorded 2026-11-26.entries_total and bytes_total are
null when the format cannot say in advance, as for a
compressed tar. For a tar, bytes_done counts the archive’s
own bytes read against its size, because the unpacked size is unknown
without a second pass. destination appears on the first
event, once the folder is known. The last event has
"phase":"done".
A failure under --ndjson-progress or -j is
one {"error": …} line on standard error after any progress
lines, so read the stream line by line and treat an object with an
error key as the verdict. In Rust, pass a callback in
ExtractHooks, and see cancellation.
The C library has no progress callback.
What is checked
These checks run on every extract, for every writable path in the CLI, the library and the C library. The evidence for each, including its limits, is on the safety model and the public safety page.
- Path containment. A name that is empty, contains a
NUL byte, starts with
/, contains a..component, or is over 4096 bytes or 64 components deep is refused withunsafe_entryorinvalid_name. A backslash counts as a separator, so..\xis refused too. The whole extract stops, so nothing from that archive is kept. - Links. A folder in the destination that is a
symbolic link is never written through. Links from the archive are made
last, and only when they resolve inside the extracted folder. A link
that leads out is skipped and listed under
skipped. A hard link is made only to a file the same archive extracted. - Size and bombs. An entry may not run more than 64
KiB past the size the archive declares for it. Output over 1000 times
the archive’s own size is stopped once 1 GiB has been written (not for
DMG or
.app). An archive of more than 1,000,000 entries is refused, and one larger than the free space is refused before anything is written. There is no fixed byte cap, so a 50 GB archive extracts if the disk has room. - Clean failure and cancel. A failed or cancelled extract into a new folder removes it. Into an existing folder it leaves only what was already there, and a merge that fails partway puts everything back.
- Permissions. Setuid, setgid and sticky bits are dropped, and the owner can always read, change and delete what was written.
- Quarantine. If the archive carries macOS’s download
warning (
com.apple.quarantine), the extracted files and folders get it too, as Archive Utility does. - Source untouched. Extracting never changes the
archive, unless you pass
--delete.
Here is a ZIP whose names try to leave the folder. Its first entry,
ok.txt, is harmless, but the extract stops at the first bad
name and the destination is never created:
peel x hostile.zip -o refused; echo "exit $?"
peel: extract hostile.zip: path escape blocked: ../escape.txt
exit 13
$ ls refused
ls: refused: No such file or directorypeel 1.4.0, recorded 2026-11-26.Links and quarantine, on a tar with one link inside and one pointing
at /etc/hosts, and on a ZIP that was downloaded:
peel x links.tar -o links -D
Tar → links (2 files)
links/real.txt
links/inside
skipped:
links/outside
$ ls links; readlink links/inside
inside
real.txt
real.txt
$ peel x downloaded.zip -o downloaded -q
$ xattr -p com.apple.quarantine downloaded/project/README.md
0081;5f000000;Safari;peel 1.4.0, recorded 2026-11-26.In Rust, the budget is ExtractPolicy::budget. The CLI
and the C library use the defaults and expose no setting.
use peel_core::{ExtractPolicy, ResourceBudget};
let policy = ExtractPolicy {
budget: ResourceBudget {
max_entries: 10_000,
max_single_entry_bytes: 1 << 30,
..ResourceBudget::default()
},
..ExtractPolicy::default()
};The limits are narrower than they sound, and the safety model page
says where they stop. Decoder memory and CPU time are not bounded
outside fuzzing. About twenty of the less common formats have no
hostile-path test file. Quarantine is best effort: it is skipped
silently on drives without extended attributes. If you write your own
extraction code, reuse sanitize_entry_name,
safe_destination, assert_tree_contained and
copy_bounded.
Cancel
On the command line, SIGINT (Ctrl-C) and SIGTERM stop an extract cleanly. Rind removes what it wrote, then ends by that signal, so a parent process sees the termination rather than an exit code.
In Rust, share a CancelFlag and call
cancel() from any thread. The extract returns
PeelError::Cancelled (ErrorKind::Cancelled)
and leaves nothing behind.
use peel_core::{extract_archive_with_hooks, CancelFlag, ExtractHooks, ExtractPolicy, ProgressEvent};
use std::path::Path;
let cancel = CancelFlag::new();
let stop = cancel.clone();
std::thread::spawn(move || { /* the user pressed Stop */ stop.cancel(); });
let mut on_progress = |ev: ProgressEvent| eprintln!("{}/{:?}", ev.entries_done, ev.entries_total);
let hooks = ExtractHooks { cancel: Some(&cancel), on_progress: Some(&mut on_progress) };
extract_archive_with_hooks(Path::new("demo.zip"), &ExtractPolicy::default(), hooks)?;In C, a PeelCancelToken stops one call and only that
call. Pass it to a _with_token call, cancel it from any
thread, and free it once the call has returned. The cancelled call
returns {"error":"cancelled",…} with no partial file.
PeelCancelToken *tok = peel_cancel_token_new();
/* On another thread, when the user presses Stop: peel_cancel_token_cancel(tok); */
char *r = peel_extract_entry_with_token("demo.zip", "project/README.md", "out", 0, tok);
peel_string_free(r); /* {"path":…} or {"error":"cancelled",…} */
peel_cancel_token_free(tok); /* only after the call has returned */Whole-archive extraction has no token variant.
peel_cancel() stops whatever is running that has no token
of its own, and it must arrive after the call has begun:
peel_extract_to and the other extract calls clear the
process-wide flag as they start. A call given a token ignores the
process-wide flag.
Next: create archives, or recover a damaged one.
void peel_cancel_token_cancel(const PeelCancelToken *token) Cancel the one call this token was passed to. Safe from any thread.void peel_cancel_token_free(PeelCancelToken *token) Free a cancel token once its call has returned.PeelCancelToken *peel_cancel_token_new(void) Create a cancel token for one call.char *peel_extract_entry(const char *archive_path, const char *entry_name, const char *dest_dir, uint64_t max_bytes) Write one entry, by its exact listed name, under dest_dir. Returns {path, size} or {symlink}.char *peel_extract_entry_with_token(const char *archive_path, const char *entry_name, const char *dest_dir, uint64_t max_bytes, const PeelCancelToken *token) peel_extract_entry, stopped by its own cancel token.char *peel_extract_to(const char *archive_path, const char *destination, uint32_t collision, uint32_t enclosing) Extract a whole archive with the policy's three fields as arguments. Reads PEEL_PASSWORD; prefer peel_extract_with_password.void peel_string_free(char *s) Free a JSON string returned by any peel_* call.peel extract Extract everything, or only the members and globs you name.peel extract Extract everything, or only the members and globs you name.