Skip to main content
coreydaley.dev

How Purrchiver is tested: 1,800 tests and 150 broken archives

An archive utility isn’t judged on the files that work. Every archive app opens a plain ZIP. It’s judged on the RAR split into twelve parts, the ZIP with Korean filenames, the download that stopped at 60%. So most of Purrchiver’s testing is aimed at the odd files.

That’s more than 1,800 automated tests today. For an archive tool, though, the interesting part isn’t the test code. It’s the test archives: where they come from, and what counts as passing.

What counts as passing

“It opened” isn’t a pass. The content tests extract an archive and compare its files, byte for byte, against the sources they were made from. Those sources have their SHA-256 checksums recorded, so a single changed byte fails the test, even if the archive opened, listed, and extracted without an error.

Archives built by scripts

More than 80 test archives (116 files, counting each part of a split set) are built by scripts, covering:

  • The formats Purrchiver opens, from ZIP, 7z, and RAR through tar’s compressed variants, ISO, CAB, LHA, .deb, .rpm, PKG, and Apple Archive.
  • Passwords: ZIP with the old ZipCrypto and with AES-128, -192, and -256; 7z and RAR5 with only the contents encrypted, and with the file list encrypted too.
  • Filenames in Chinese, Japanese, Korean, Cyrillic, Arabic, and Hebrew, in ZIP, 7z, and RAR, and emoji filenames in ZIP.
  • Size edges: an empty ZIP, a ZIP holding one zero-byte file, a ZIP with 100,000 entries, folders nested 50 deep, and a path more than 6 KB long.
  • The 4 GiB line, crossed one byte at a time: archives holding a file of 4 GiB minus one byte, exactly 4 GiB, and 4 GiB plus one byte. That’s where ZIP needs its 64-bit extension, and where older tools break. The source files are sparse, so each test archive is only about 4 MB.
  • Multi-part RAR5 and 7z sets, and archives with hard links, permissions, and macOS metadata.

The generators pin file timestamps and take their “random” data from a fixed seed, so the files inside each archive are identical on every run, even when a tool like rar packs them slightly differently.

At first the archives were regenerated on every CI run. That meant installing seven command-line tools on every run, one of them RARLAB’s commercial rar, and it added a couple of minutes to every push. So the archives are now checked in alongside the scripts that made them, every test run checks the same files, and the scripts remain the record of how each one was built.

Archives other projects collected

Some archives can’t be generated, because the point is that someone else made them.

More than 450 test files come from other projects, each pinned to a specific upstream version with its license recorded. None of it ships in the app.

From libarchive’s own test suite: 43 archives, including real output from WinZip, GNU tar, and Solaris tar, ZIPs with Japanese and Russian code-page file names, encrypted ZIP and 7z variants, and a RAR4 file, which RARLAB’s current rar can no longer write. Each is opened and checked against the result libarchive’s own tests expect. Where Purrchiver doesn’t match yet, the test is marked as a known issue, so a fix shows up as an unexpected pass.

Files with a documented outcome: intact ZIPs from the yauzl project with the exact folders they must extract to; xz-utils’ test files (from version 5.8.4, after the 2024 backdoor files were removed), where every good- file must decode and every bad- file must fail; and bzip2’s test files, each with the checksum its output must match. These caught three real bugs: a damaged header passed through as if it were the decompressed data, text like Hello\nWorld! mistaken for a file listing, and data starting with zeros read as an empty tar, so a .tar.gz came out as only its first file.

New in Purrchiver 1.1. If you don't see it, update Purrchiver from the App Store.

For recovering damaged archives, new in Purrchiver 1.1: more than 150 deliberately broken archives from the test suites of libarchive, Go’s archive/zip and archive/tar packages, Apache Commons Compress, yauzl, and py7zr. Malformed headers, truncated files, size fields that overflow, and regression files for crashes and hangs those projects hit, some of them found by their fuzzers. Every one goes through a normal open, an extract, and recovery, each with a one-minute time limit, and the bar is:

  • nothing crashes and nothing hangs;
  • recovery reports damage instead of failing with an error, except when it needs a password or hits the size limit;
  • nothing is written outside the destination folder, and no links are created;
  • every partly recovered file says “(incomplete)” in its name;
  • every file recovery says it wrote is really there.

Update, October 23: to be exact, that test opens and lists each file, then runs recovery on it. There’s no separate extract pass over this set.

This set found real bugs on its first runs. Go’s dupdir.zip contains a file and a folder with the same name, a/b. Recovery hit “file exists” and lost the whole result. Now it keeps the file and reports what was inside the folder as unrecoverable. A tar with a file name longer than macOS allows made recovery give up on everything; now only that file is lost.

The full story is in Recovering what’s readable from a damaged archive.

For repairing archives from recovery data, also new in 1.1: test files from nine of par2cmdline’s own tests, plus Rust-PAR2’s repair scenarios, run against Purrchiver’s PAR2 implementation, which was written from the specification rather than from par2cmdline’s code. There are sets to repair, sets whose hashes are deliberately wrong, a malformed set that must be refused, and multi-file sets, which Purrchiver doesn’t handle yet and must turn down plainly. One case is a flipped bit whose block CRC32 still matches; only the MD5 check catches it, so the test makes sure Purrchiver does too. Recovery files with hostile numbers (sizes past the largest integer, absurd slice counts) used to crash the app; they’re now refused.

Update, October 23: Purrchiver 1.1 now repairs sets that cover several files, the usual case for a multi-part RAR. Those same par2cmdline sets are now checked and repaired as sets: damaged and missing files are rebuilt into a new folder and each one must match its MD5. Only the check for a single file still turns a multi-file set down.

The real tools, in both directions

A round trip through Purrchiver alone proves less than it seems. If the writer and the reader share a bug, the archive goes out wrong, comes back “right”, and the test passes. So ZIP, 7z, tar and its compressed variants, the single-file compressors, ISO, CPIO, and Apple Archive are each tested against the tool people actually use, with the same source files, in both directions for most of them:

  • Purrchiver writes, the other tool reads, and the result is compared byte for byte.
  • The other tool writes, Purrchiver reads, and the same comparison runs.

The tools are 7-Zip’s 7zz, Info-ZIP’s zip and unzip, tar, gzip, bzip2, xz, zstd, lz4, lzip, Brotli, cpio, and Apple’s aa (for both Apple Archive and its encrypted form) and ditto. For formats Purrchiver only reads, like RAR, the test archives come from the real tool (RARLAB’s rar) and only the reading direction applies. If a tool isn’t installed, its tests skip rather than fail, so the suite still runs on a Mac that has only some of them.

This is how encrypted 7z is held to account: an encrypted 7z that only Purrchiver can open would be worse than no 7z encryption at all.

Testing the app, not just the engine

Correct archives don’t help if the app around them is wrong, so the tests go past the archive code:

  • About 115 UI tests drive the real app: create an archive in its windows, open it, extract it, and check the files on disk. They run on a separate Mac, because UI tests take over the machine they run on. (More on what UI tests do to a Mac.)
  • The built app gets its own checks: entitlements are read from the signed app, and a Release build is scanned to prove debug-only code isn’t in it. Test the signed binary, not the source.
  • The one-time unlock is tested with StoreKit’s test environment, which has its own trap.
  • Settings are tested by their effect. Change a setting, make a real archive, and check that the output changed. That’s the fix for settings that saved and did nothing.
  • The full run is one command, run the same way on my Mac and on the test Mac, so a pass on one means the same as a pass on the other.

What the tests guard

Several posts on this blog are about a specific failure and the test that now stands in its way:

What isn’t covered

Purrchiver doesn’t run its own fuzzer yet. The broken-archive corpus includes cases other projects’ fuzzers found, but that’s not the same as fuzzing Purrchiver directly. Passwords with non-ASCII characters aren’t supported yet for ZIP, 7z, or RAR; Purrchiver refuses them with a clear message, and a test holds it to that. And tests prove what they check, nothing more. When something gets through, it gets a test of its own.

The short version is on How Purrchiver is tested.

Related posts