omega-zip
I wrote omega-zip so that a zip file, a zlib stream or a raw DEFLATE stream can be read by a tool whose every line anyone can inspect. It is written in Omega (seeded Omegese) and built by the pinned seed-born compiler; nothing else runs inside it. It is the first engine of the no-black-box tools (slice S1): Office files (.docx, .xlsx, .pptx, .odt) are zip archives, and most PDF streams are zlib.
One program, ozip:
| command | what it does |
|---|---|
ozip crc32 | CRC-32 of stdin, 8 lowercase hex digits and a newline |
ozip inflate | raw DEFLATE (RFC 1951) on stdin to stdout |
ozip zlib | a zlib stream (RFC 1950) on stdin to stdout, Adler-32 checked |
ozip l ZIP / ozip v ZIP | list the entries, byte for byte what Info-ZIP UnZip 6.0 prints for unzip -l / unzip -v (name, sizes, method, CRC, date) |
ozip t ZIP | decompress every entry and check its CRC-32, no output |
ozip p ZIP [NAME] | every entry (or the one named, an exact name) to stdout, like unzip -p |
ozip x ZIP DIR [NAME] | extract into the existing directory DIR |
Stored (0) and deflated (8) entries are read; the CRC-32 of every extracted entry is checked.
What the proof proves, and what it does not
The gate below proves that the ozip built from exactly these sources by the pinned compiler gives
the oracle's bytes on the corpus, refuses the malformed inputs with the stated codes, kills the stated
mutants, and never traps or hangs on 32,960 cut or changed inputs. It does not prove that ozip is
correct on every input, that it is fast, or that a file it reads is harmless: it reads what the archive
says, within the bounds below.
Build
The compiler is omega-mv's seed-born seed/out/omc at the commit in PIN (sha256 in PIN). With an
omega-mv checkout at that commit (sh seed/omega-from-seed.sh rebuilds omc from the seed and must give
the same sha256):
OMC=/path/to/omega-mv/seed/out/omc
cat src/head.om vendor/omega-mv/seed/text/text.om src/io.om src/crc32.om src/inflate.om \
src/zlibd.om src/unzip.om src/main.om | $OMC > ozip && chmod +x ozip
The units must be in that order (src/head.om carries the om2 line). The output is a static Linux
AArch64 executable. tests/gate.om builds the same way (its UNITS text) and is the receipt.
Gate
mkdir -p build && $OMC < tests/gate.om > build/gate-bin && chmod +x build/gate-bin && build/gate-bin $OMC
Run from the repository root. The last line on success:
OZIPGATE PASS cases=219 mutants-killed=19/19 robust-runs=32960
It exits 0 on PASS, 1 on any failure, 3 (NOT_RUN) when the compiler's SHA-256 is not the pin. It computes that SHA-256 itself (FIPS 180-4). Then it:
- builds
build/gate/ozipfrom the units; - runs the 219 cases of
tests/cases.txt: exit status, stdout against the oracle's bytes, and stderr (empty after success; exactly one lineozip: ...after a refusal), plus extraction checks (xcmp,xabsent: the extracted file equals the original; nothing was written outside DIR); - builds each of the 19 mutants of
tests/mutants.txt(one source line replaced: a wrong distance base, a wrong length base, a 16 KiB window, no distance-too-far check, no stored length check, a wrong CRC polynomial, no CRC check, no path check, no local header check, no Adler-32 check, no local name, method or flag comparison, no descriptor size comparison, no data-before-directory check, no directory size or end check, no ZIP64 size sentinel, no overlap check) and requires a failing case for each; - robustness: every raw, zlib and zip corpus file (103 files) cut at 64 points and changed at 256
single bytes; every run must end with 0 or a documented code, never a trap (exit 101..114), a
signal or the 10 s limit, and an exit 0 of
zliborpmust give the oracle's bytes. Raw DEFLATE has no checksum, so a changed byte may decode to other bytes; those runs are counted, not failed.
The oracles are test tools only, never part of omega-zip: python3 zlib (Python 3.12.3, zlib 1.3) and
Info-ZIP UnZip 6.0 / Zip 3.0. Their output is committed under corpus/ with the commands that made it
(corpus/SOURCES.txt), so the gate itself needs only the pinned omc. corpus/refuse/ORACLE.txt has
the oracle's verdict on each refusal fixture. tests/mkcases.om (Omega) regenerates corpus/refuse.
Exit codes
Every refusal writes one line ozip: MESSAGE to stderr. Output already written to stdout before a
refusal stays written (the stream is not buffered whole); with x the partly written file is removed.
| code | meaning | zlib's message for the same input (python3) or UnZip |
|---|---|---|
| 0 | done | |
| 1 | usage, bad arguments | |
| 2 | cannot open the zip file | |
| 3 | read error | |
| 4 | write error | |
| 5 | x: cannot create an output file or directory (it may exist already: files are opened with O_EXCL and O_NOFOLLOW, never overwritten) | |
| 10 | input ends early (also: empty input) | incomplete or truncated stream |
| 11 | invalid block type (3) | invalid block type |
| 12 | stored block length does not match its complement | invalid stored block lengths |
| 13 | too many length or distance codes (HLIT > 286 or HDIST > 30) | too many length or distance symbols |
| 14 | code-length code over-subscribed or incomplete | invalid code lengths set |
| 15 | code-length repeat with no previous length, or past the end | invalid bit length repeat |
| 16 | literal/length code lengths over-subscribed or incomplete (one code of length 1 is admitted) | invalid literal/lengths set |
| 17 | distance code lengths over-subscribed or incomplete (likewise) | invalid distances set |
| 18 | no end-of-block code (symbol 256 has length 0) | invalid code -- missing end-of-block |
| 19 | invalid literal/length code (286, 287, or no code) | invalid literal/length code |
| 20 | invalid distance code (30, 31, or no code) | invalid distance code |
| 21 | distance too far back (before the start of the output) | invalid distance too far back |
| 22 | output above the bound (4294967295 bytes per stream; CRC-32 input above 2^40 bytes) | |
| 30 | bad zlib header (method not 8, window above 32 KiB, check bits) | incorrect header check / unknown compression method / invalid window size |
| 31 | zlib preset dictionary | Error 2 (Z_NEED_DICT) |
| 32 | Adler-32 mismatch | incorrect data check |
| 40 | no end of central directory record (not a zip file) | |
| 41 | ZIP64 archive: not yet supported | |
| 42 | split or spanned archive | UnZip warns and tries anyway |
| 43 | encrypted entry | UnZip asks for a password |
| 44 | compression method other than 0 and 8 | |
| 45 | x: unsafe name (absolute, .., ., empty part, backslash, NUL), or output path above 4095 bytes | UnZip strips ../ with a warning |
| 46 | local header or data descriptor disagrees with the central directory | stricter than unzip -t |
| 47 | CRC-32 mismatch | bad CRC |
| 48 | entry larger than the bound (1 GiB) | |
| 49 | no entry with that name | |
| 50 | central directory malformed (signature, count, size, offsets) | |
| 51 | entries overlap: their local headers and data need more bytes than lie before the central directory (an overlapping zip bomb) | UnZip: "invalid zip file with overlapped components (possible zip bomb)" |
| 52 | stored entry with different compressed and uncompressed sizes | |
| 53 | entry data longer or shorter than its stated size | stricter than unzip -t |
A trap (exit 101..114) would be a defect: the gate fails on one.
Bounds, and what happens at each
Nothing holds a whole file. All storage is fixed: 57 globals, 64,124 bytes in all (a 32 KiB window
that is also the output buffer, a 16 KiB input buffer, Huffman tables, a 4 KiB name, a 4 KiB wanted
name, a 4 KiB output path), plus at most 12,376 bytes of local arrays. No array has more than 32,768
elements, so the sizes of profile rule B3 (seed/profile/README.md: 65,536 elements per array, 65,536
bytes of globals) hold. The B1 loop-bound rule (every bound at most 8192) is not met: streaming a file
of up to 4 GiB in one pass needs outer loops above 8192 passes, so the unit is not profiled.
| bound | value | at the bound |
|---|---|---|
| window (distance) | 32768 bytes (RFC 1951) | a larger distance cannot be coded |
| output per raw or zlib stream | 4294967295 bytes | refused, 22 (bytes before it already written) |
| CRC-32 input | 2^40 bytes | refused, 22 |
| zip entry, uncompressed | 1073741824 bytes (1 GiB) | refused before any output, 48 |
| zip entry output vs its stated size | exactly the stated size | refused, 53 |
entries' local headers, names and data, summed over the archive (t, p, x) | at most the bytes before the central directory, so the output is bounded by DEFLATE's ratio times the archive size | refused before any output, 51 |
| zip entries | 65535 (no ZIP64) | 0xFFFF means ZIP64: 41 |
| archive comment | 65535 bytes (the end record is searched in the last 65557 bytes) | not found: 40 |
| entry name | 4095 bytes | 45 |
x path DIR/NAME | 4095 bytes (Linux PATH_MAX - 1) | 45 |
| ZIP path argument, DIR argument | 4095 bytes | 1 |
| directories | made with mode 0755; files 0644 |
Not supported (refused, never guessed)
ZIP64 (not yet supported: 41), encryption (43), split or spanned archives (42), methods other than
stored and deflated (44: no BZIP2, LZMA, Deflate64, ...), archives with data before the first entry
(self-extractors: the offsets no longer match, 50), zip symbolic links and file modes (an entry is
written as a plain file with mode 0644), archive comments in t/p/x are ignored, gzip files (use
ozip inflate after the gzip header is removed). ozip p NAME takes the exact name, without
UnZip's wildcards. The l/v listings are equal to UnZip's for archives whose entries carry no
extended-timestamp extra field (UnZip then prints that time in the local time zone; omega-zip prints the
MS-DOS date and time fields) and whose names are printable ASCII (control bytes are shown as ^ and
the byte plus 64, as UnZip does). Output files are not given the archive's timestamps.
Measured speed
MEASURED 2026-11-10T04:53Z on the Spark (DGX Spark GB10, Linux AArch64), one core: taskset -c 8
inside the hive's pool-8-9 ticket, nice -n 10, load average about 20 on the machine. ozip built by
the gate (sha256 3687bb9d...981d76); wall time of /usr/bin/time (0.01 s resolution), the same in
each of 3 runs; MiB per second of uncompressed output (Wolfram: 64/0.47, 64/0.28, 128/0.99, 64/0.13).
| command | input | time | throughput |
|---|---|---|---|
ozip inflate | text64M.raw6: 64 MiB of OMEGESE.md repeated, python3 zlib level 6 raw, 25,504,782 bytes | 0.47 s | 136.2 MiB/s out (51.8 MiB/s in) |
ozip inflate | bin64M.raw6: 64 MiB of omc repeated, level 6 raw, 14,554,550 bytes | 0.28 s | 228.6 MiB/s |
ozip t | tp.zip: both files, zip -6, 40,051,393 bytes, CRC-32 checked | 0.99 s | 129.3 MiB/s |
ozip crc32 | text64M | 0.13 s | 492.3 MiB/s |
The output bound was exercised once outside the gate (it needs 4 GiB of output): 4294967296 zero
bytes compressed at level 9 (4,174,507 bytes) gave ozip: output above the bound, exit 22, after
5.99 s. The inputs are made by commands in the scratch directory and not committed; they are not part
of the corpus. Huffman codes are decoded one bit at a time (simple to read, not the fastest way).
Standards followed
- RFC 1951, DEFLATE Compressed Data Format Specification version 1.3 (sections 2, 3.2.1 to 3.2.7).
- RFC 1950, ZLIB Compressed Data Format Specification version 3.3 (sections 2.2 and 8.2, Adler-32).
- PKWARE APPNOTE.TXT, .ZIP File Format Specification, version 6.3.10 (sections 4.3.6 to 4.3.16, 4.4).
- CRC-32: the polynomial of ISO 3309 and ITU-T V.42 (0x04C11DB7, reflected 0xEDB88320), register preset to all ones and inverted at the end, as APPNOTE 4.4.7 and RFC 1952 section 8 specify.
- SHA-256 in the gate: FIPS 180-4.
Files
src/: the units (head,io,crc32,inflate,zlibd,unzip,main).- Reuse: another program can take
io.om,crc32.om,inflate.om,zlibd.omandunzip.omunchanged. Their output goes throughw = wout n(the windowwin[0 .. n)), which the program defines asfn wout n ulong to ulong, returning n:src/main.ompasses it towoutfdinio.om(the output descriptor); omega-office'ssrc/sink.omconsumes it. Without awoutomc refuses the program (error 3). vendor/omega-mv/seed/text/text.om: omega-mv's text unit, unchanged (NOTICE,PIN).tests/gate.om,tests/cases.txt,tests/mutants.txt,tests/mkcases.om.corpus/: originals, oracle outputs, refusal fixtures; sources and licences incorpus/SOURCES.txt.
Licence
Apache-2.0 (LICENSE). The LibreOffice templates in corpus/zip are MPL-2.0 test data (NOTICE).