Repository navigation
fix(artifacts): read ASCII control bytes in legacy ZIP names as ASCII - #2365
Conversation
ZIP names without the UTF-8 flag were decoded with zip.js's CP437 table, which maps bytes 0x01-0x1F and 0x7F to IBM PC display glyphs. A folder zipped on macOS with a custom icon therefore listed and extracted `Folder/Icon\r` as `Folder/Icon♪`, a name that is not in the archive and differs from REA's directory inventory of the same folder. Tabs became `○` and DEL became `⌂`. Decode legacy names in REA's existing decodeText hook with the Unicode CP437 mapping that Python's zipfile also uses: bytes below 0x80 as ASCII, and the upper half with the same table zip.js uses. Windows file names cannot contain U+0001-U+001F, so a Windows extraction destination now refuses such a path with a typed path failure before creating anything, as it already does for ':'.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Review Finding & Edge CaseIn if (platform === "win32" && /[\u0001-\u001f]/u.test(path))
throw new ArtifactReaderFailure(
"path",
`Windows destination cannot materialize artifact path: ${JSON.stringify(path)}; Windows names cannot contain U+0001-U+001F.`,
);Finding: Incomplete Windows Forbidden Character Coverage
Suggested FixUpdate the Windows invalid character regex in if (platform === "win32" && /[\u0001-\u001f\u007f]/u.test(path)) |
|
@greptileai review |
|
This PR is set for a Plus review. TREX isn't supported with Plus or Apex reviews yet, so Greptile reviews this PR at Base while TREX is on. |
|
The control-name cases checked only the logical path that inventory reports. Extraction writes through SafeOutputTree, so a change that renamed the extracted files would still pass those cases. Extract `Icon\r` and `é\t\u007F.a`, then compare the reported relative_path, the directory listing, and the file contents. The new cases skip on Windows, which refuses these names. safeOutputTree.test.ts covers that refusal.
|
@matbrgz Windows allows U+007F in file names. The Win32 naming rules allow any character except NUL, the characters 1 through 31, and |
Summary
ZIP member names without the UTF-8 flag kept zip.js's display glyphs for ASCII control bytes. A folder with a custom macOS icon, zipped with
zip -r, holdsFolder/Icon\r; REA listed and extracted it asFolder/Icon♪, a name that is not in the archive. Legacy names now decode bytes below 0x80 as ASCII, so the member keeps its real name in the inventory and on disk. Windows extraction destinations, which cannot hold such names, now refuse them with a typed path failure before creating anything.No issue is linked. I found this while comparing
inspect-artifactandextract-artifactwith Python'szipfileon synthetic archives.Problem and expected behavior
Smallest trigger: a ZIP entry whose name contains a byte in 0x01-0x1F or 0x7F and whose general-purpose flag lacks the UTF-8 bit. Info-ZIP
zipleaves the flag clear for ASCII names, soIcon\rtakes this path.ZipArtifactReaderpassed names without the UTF-8 flag to zip.js's built-in CP437 decoder. That table maps 0x01-0x1F and 0x7F to IBM PC display glyphs (\rto♪,\tto○, DEL to⌂). The Unicode CP437 mapping, which Python'szipfileuses, keeps 0x00-0x7F as ASCII. Expected: the logical path and the extracted file name are the bytes the archive stores, as they are for a directory target holding the same folder.Change and scope
decodeZipEntryText, REA's existing zip.jsdecodeTexthook, now decodescp437file names itself. Bytes below 0x80 decode as ASCII. The upper half uses the same CP437 table zip.js uses, so names such asé.txtkeep their current decoding. UTF-8 names and comments are unchanged.Windows file names cannot contain U+0001-U+001F.
SafeOutputTreealready refuses:on Windows destinations before creating anything; it now refuses these characters the same way, with anArtifactReaderFailureof reasonpath. Before this, a directory component with such a character reachedmkdiron Windows. UTF-8 flagged names could already carry these characters, so the refusal also covers them.Out of scope: archives that store UTF-8 bytes without setting the flag still decode as CP437, as the ZIP specification requires. Other Windows naming rules (reserved device names,
<>"|?*, trailing dots or spaces) are not checked bySafeOutputTree;src/adb/AdbHostFileName.tsalready encodes them for adb pulls.Contribution scope: not applicable (ordinary fix within existing boundaries).
Contract and boundary impact
decodeZipEntryTextinsrc/artifacts/ZipArtifactReader.ts, where ZIP names enter REA, andnormalizeDestinationPathinsrc/artifacts/SafeOutputTree.ts, which owns destination naming rules.ZipArtifactReader; the destination refusal applies only when the destination platform iswin32.docs/public/product-catalog.json), package, or installation impact: none.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
The checked file change is
extract-artifactwriting members under its existing output root, now with their real names.Evidence and regression coverage
Tests added or updated:
tests/boundary/filesystem/artifactZipIntegrity.test.tsadds two cases to "preserves %s ZIP member names",Icon\rand the mixed nameé\t\u007F.a, each without the UTF-8 flag. Each checks the inventory's logical path with a verified hash. Outside Windows, "extracts %s ZIP members under their stored names" extracts the same two names throughextract_artifactand checks the reportedrelative_path, the directory listing, and the file contents.tests/boundary/filesystem/safeOutputTree.test.tsadds "refuses Windows control characters before creating %j" for a file name (Folder/Icon\r) and a directory name (Fold\ter/file.txt) on awin32tree, and checks that nothing was created and rollback completes.Base reproduction or other evidence: with
ZipArtifactReader.tsandSafeOutputTree.tsrestored frommain(fd95880), the four new name cases and the two Windows cases fail; the other tests in both files pass, and one Linux-only test is skipped. A probe that replaces control characters with_innormalizeDestinationPathfails only the two extraction cases.User-visible CLI/MCP output (if applicable): a folder holding
Icon\randreadme.txt, zipped withzip -qr icon.zip Folder.Before (
main), logical paths fromrea inspect-artifact, thenrelative_pathfromrea extract-artifactand the extracted directory listing:After:
Remaining proof gaps: I tested archives written by Info-ZIP
zip, not archives from other producers. The Windows refusal is tested throughSafeOutputTree.create(output, "win32")on macOS, not on a Windows host.For evidence-bearing changes:
Validation performed
mainfd95880, with dependencies installed bynpm ci:npm run check:fastpasses.npm run test:focusedover 99 test files covering artifacts, archives, ZIP reading and safe output (tests/boundary/filesystem/,tests/boundary/providers/native/artifactProvider*, the MCP extraction suite andsrc/artifacts/). 918 pass and 2 are skipped.npm run build:cachedon each checkout.npm run check:fastpasses on Node 24.18.0.npm run test:focusedoverartifactZipIntegrity.test.tsandsafeOutputTree.test.tspasses 34 tests and skips 1.Compatibility, safety, and release
zip3.0 (Apple build) and Pythonzipfileas the oracle.Before merge
type(scope): outcome.