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.

Peel 1.4.0 · Snack Studio · Updated

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.

TerminalShell
peel extract demo.zip -o out -j
JSON
{
  "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:

In Rust that is EnclosingDirectory::WhenNeeded, Always or Never, and in C the enclosing argument is 0, 1 or 2.

Rust
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());
C
/* 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.rs
Real output from peel 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:

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.md
Real output from peel 1.4.0, recorded 2026-11-26.
No match is not an error. A pattern that selects nothing extracts nothing and exits 0, with 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.

C
/* 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:

  1. --password-stdin reads it from standard input. One trailing newline is dropped.
  2. --password-fd N reads it from a file descriptor your process inherited.
  3. PEEL_PASSWORD works for scripts, but any process of the same user can read it while peel runs (ps eww shows it). peel removes the variable from its own environment at start, so nothing it launches inherits it.
  4. -p or --password puts the password on the command line, where ps shows 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.

TerminalShell
security find-generic-password -s backup -w | peel x locked.zip -o out --password-stdin
printf '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
project
Real output from peel 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.

Rust
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.

TerminalShell
peel x bundle.zip -o out --deep

Watch 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}
Real output from 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.

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 directory
Real output from peel 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;
Real output from 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.

Rust
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.

Safe to extract is not safe to run. These checks protect where bytes are written and how many. They say nothing about what the files do once you open them.

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.

Rust
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.

C
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.