Extract archives in pure Lua with a vendored zzlib #4
Reference in New Issue
Block a user
Delete Branch "benvin/vendor-zzlib"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Installing a plugin needed unzip or tar on PATH, which rules out machines
without them, and left archive path safety entirely to those tools.
Reviewed by building hostile zip/tar fixtures byte-by-byte (Python) and running the real
archive.luaagainst them, plus a real-world equivalence test.Verified clean (no repro found):
../(shallow/deep/mixed), absolute paths,C:drive, backslashes, embedded NUL, empty/./../normalizes-to-parent names, symlink/hardlink/device/fifo/setuid entries (zip external_attr and tar typeflags), encrypted zip entries, GNU-L / pax-x / ustar-prefix tar path overrides — all rejected, nothing written outsidedestin any case.plenary.nvimv0.1.4 zip (160 entries, 125 deflated) and tar.gz extracted with oldunzip/tarvs. new code:diff -rqand file-mode listings identical.zzlib.lua/inflate-bit32.lua/inflate-bwo.luadiffed byte-for-byte against upstream9c39321: only the documented header comment + the two documented changes (namespaced requires, crc32 re-export) — nothing silently edited.luacheck lua tests= 0 warnings (ran for real in a container); theMODE_EXEC/MODE_FILE/MODE_EXEC_FILE"unused locals" concern doesn't reproduce — all three are used (archive.lua:91,229,333).stylua --checkpasses. Full suite (119 tests) passes, and still passes withunzip/tar/zipremoved from PATH entirely.archive_root()untouched; commits properly split (vendor lib / integration); PR body within the line/char cap.Two non-security nits (nice-to-have, not blocking):
lua/arti-pack/archive.lua:159(zip_entries) — a central-directory entry truncated right before its namelen/extralen fields makesu16()returnnil, sopos = pos + 46 + namelen + u16(buf,pos+30) + u16(buf,pos+32)raises a raw Lua error ("attempt to perform arithmetic on a nil value") instead of the module's usualnil, "malformed central directory".fs.extract'spcallwrapper catches it today so nothing crashes in the real install path, butarchive.unzip/archive.extractcalled directly throws, and the surfaced message is an internal error string instead of a clean one. Suggest adding apos + 46 > #bufbounds check next to the existingu32(buf,pos) ~= CD_SIGguard so this fails the same clean way as the other malformed-CD cases.tests/archive_spec.lua— thezipf()fixture builder hardcodesmethod=0(STORED) for every entry, so no test ever builds a DEFLATE (method=8) zip entry: the actual zzlib inflate path — the highest-risk code here, since it parses attacker-controlled compressed bytes — has zero direct test coverage. "fails loudly on a CRC mismatch" only exercises the stored path. The existinggz()helper already proves a stored-block (BTYPE=00) DEFLATE stream is enough to build valid compressed data without a real compressor; the same trick would letzipf()support a deflated entry and a deflated CRC/size-mismatch case.unkin-agent referenced this pull request2026-09-10 23:28:47 +10:00