Repository navigation
fix(artifacts): admit ZIP archives after unclaimed leading bytes - #5803
Conversation
ZIP recognition required the archive at byte 0, so a ZIP behind a script or self-extractor stub was refused as an unsupported binary format although standard readers accept it. Target resolution and root inventory now locate a trailing single-disk ZIP from its end record, central directory and first local header, whether member offsets include the leading bytes or not. Leading bytes any executable header family claims keep their executable route. Fixes #5732 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 41948cc6a5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
[Medium impact] The PR appears safe to merge; no blocking issue was established. SummaryAdds trailing ZIP recognition for files whose leading bytes are not claimed by another format.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Root file] --> B{Existing format recognized?}
B -->|Yes| C[Keep existing route]
B -->|No| D{Executable header claimed?}
D -->|Yes| C
D -->|No| E[Locate trailing ZIP]
E -->|Not found| F[Keep rejection or generic classification]
E -->|Found| G[Shared root ZIP package mapping]
G --> H[Existing ZIP reader and extraction checks]
Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
The trailing-ZIP fallback named a stub-prefixed root `.app` archive `zip`, while root inventory and the leading-signature route name it `app-pack`. The root mapping now lives once in `zipRootPackageFormat` and both target resolution routes and root inventory use it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What broke:
inspect-artifactandextract-artifactrefused a valid ZIP behind a script or self-extractor stub as "unsupported binary format", although Info-ZIP, bsdtar and Python read it (#5732).Fix: target resolution and root inventory now locate a trailing single-disk ZIP from its end record, central directory and first local header. This applies only when no other format claims the leading bytes; executable-led files keep their executable route.
Risk: low to medium. It is additive for previously refused files. Classification stays unchanged for files any existing format recognizes, and Zip64, split and empty archives still fail closed.
Summary
Fixes #5732. A ZIP preceded by inert leading bytes, such as a
#!/bin/shstub or a self-extractor, was refused before inventory or extraction because ZIP recognition only checked the first four bytes. Both prefix styles in common use now inventory and extract with the same verified member bytes as the plain archive:zip -A, or Python'szipfileappending to the stub);Problem and expected behavior
Trigger: a 17-byte shell stub followed by a ZIP. Before this change, on main
d672cc239(macOS arm64),inspect-artifactreturnedtarget_unavailable/ "Cannot open artifact: unsupported binary format." for both prefix styles, while the plain ZIP passed.Expected: a file whose leading bytes are claimed by no other format, and which ends in a structurally consistent ZIP, is a ZIP archive. A file whose leading bytes begin an executable header keeps the executable classification. For example,
/bin/lswith an appended ZIP staysmach-o-universal.Change and scope
src/domain/zipPackageFormat.tsnow owns ZIP recognition at both ends of a file:hasZipSignaturefor the start and the newlocateTrailingZipArchivefor a trailing archive. The locator takes an injected positional read and is bounded to the last 22 + 65,535 bytes, one 46-byte central-directory header and one 4-byte local-header signature. It requires:src/domain/binaryTarget.tsaddsclaimsExecutableHeader, which recognizes the ELF, MZ, Mach-O and FAT families thatparseExecutableHeaderinterprets, whether or not the header is valid. Both callers use it, so they make the same decision.BinaryTargetResolverconsults the locator only after native header detection fails and only when no executable family claims the leading bytes. Root inventory classification (classify.ts) consults it only when the bytes classify asfileorunknownand no executable family claims them.ZIP_NON_ENTRY_LIMITATIONnow names leading bytes before the first entry, such as a self-extractor stub, as non-entry bytes that are not occurrences.Not included:
Admitting any of these would need a separate decision.
Scope decision: not applicable. This is format recognition within the existing ZIP reader boundary. The reader (
@zip.js/zip.js2.15.0) already reads both prefix styles, as verified below.Contract and boundary impact
src/domain/zipPackageFormat.ts, consumed by target resolution and root inventory classification.zipartifact inventories and extractions.Expected effects:
Evidence and regression coverage
tests/acceptance/artifactZipLeadingBytes.test.ts: the public CLIinspect-artifactandextract-artifacton a script-stubbed ZIP. It checksziproot format, verified members, the non-entry limitation, and the extracted bytes. This fails on the base revision withtarget_unavailable.tests/boundary/filesystem/zipDetection.test.ts:zipthrough root classification andparseBinaryTarget, with member identities equal to the plain archive's.tests/boundary/filesystem/artifactComparison.test.ts: updated for the widened limitation text.d672cc239):plain.zippassed;prefixed.zip(offsets include the stub) andconcat.zip(raw concatenation) failed with "unsupported binary format".a.txt,d, andd/b.txtasverified, and extract members with identical digests./bin/ls+ ZIP staysmach-o-universal.@zip.js/zip.js2.15.0 reads both prefix styles. For raw concatenation it rebases entry offsets itself (a.txtat offset 17).inspect-artifacton the concatenated file): root formatzip; occurrences.,a.txt,d,d/b.txt, allverified.locateTrailingZipArchivetakes 0.112 ms per call on a 50 MB unrecognized random file and 0.023 ms on the prefixed ZIP. It runs only for files that no other format claims; the cold-cache cost of one ≤64 KiB tail read was not measured separately.For evidence-bearing changes:
Validation performed
npm run test:focused -- tests/acceptance/artifactZipLeadingBytes.test.ts tests/boundary/filesystem/zipDetection.test.ts tests/boundary/filesystem/artifactComparison.test.ts tests/acceptance/artifactZipCurrentDirectory.test.ts tests/acceptance/artifactZipExtractionPaths.test.ts tests/acceptance/pyinstallerArchive.test.ts tests/acceptance/godotPck.test.ts src/artifacts/ZipArtifactReader.test.ts src/artifacts/apple/machoContainer.test.ts: 76 passed.npm run test:focused --every test file that referencesparseBinaryTarget,classifyAndHashRoot,BinaryTargetResolverorparseExecutableHeader(46 files): 822 passed, 1 skipped.npm run check:fast: passed (typecheck, lint).npm run format:check: passed.CLI reproduction and non-regression checks above: passed.
Review follow-up (93e5576): the root ZIP family mapping (
.app→app-pack) now lives once inzipRootPackageFormatand is shared by both resolver routes and root inventory; a stub-prefixed rootExample.appisapp-packfrom both.zipDetection+ CLI acceptance: 25 passed;check:fast,format:checkpassed. The first CI run failed onlypeResources(30 s timeout, also seen on main on 2026-10-20); it passed locally in 9 s.Compatibility, safety, and release
Author readiness
Human owner: @kaoru0822-kitauji
Before merge
type(scope): outcome.🤖 Generated with Claude Code