Skip to content

fix(artifacts): report malformed ZIP archives as format failures - #2683

Merged
morluto merged 6 commits into
mainfrom
fix/zip-format-failures
Oct 13, 2026
Merged

morluto merged 6 commits into
mainfrom
fix/zip-format-failures

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Problem

rea inspect-artifact (and inventory_artifact / extract_artifact) on a truncated or corrupt ZIP/APK/JAR returned:

{"code":"artifact_operation_failed","message":"Artifact could not be read or written. Check file access and try again.","details":{"operation":"inspect_artifact","reason":"io"}}

The file is readable; the archive is malformed. The io reason gives the wrong advice and drops the reason.

Root cause

zip.js throws plain Errors for archive faults (End of central directory not found, File format is not recognized, Overlapping entry found, Invalid compressed data, Compression method not supported, …). ZipArtifactReader passed them through untyped, so translateArtifactFailure's fallback turned each one into ArtifactOperationError(…, "io") with no detail.

Fix

The fix is at the producing boundary, ZipArtifactReader. zip.js faults are matched against its exported ERR_* constants and converted into typed ArtifactReaderFailures:

  • format for structural and data corruption (EOCD/central directory/local header missing, bad format, overlapping or out-of-bounds entries, invalid CRC/compressed data/size, ambiguous archive)
  • unavailable for unsupported archive features (compression method, encryption method, encrypted central directory, split archives)

The typing covers all three paths an error can take: entry enumeration, the getData rejection, and the WritableStream abort. Corrupt-data errors reach the abort path first. Unrecognized errors (real filesystem I/O) are passed through unchanged.

After the fix:

{"message":"Artifact is invalid or has changed. Get a fresh copy and try again.","details":{"operation":"inspect_artifact","reason":"format","detail":"ZIP archive is malformed: End of central directory not found"}}

Other ZIP consumers (Flutter APK reader, JADX JAR probe, SAZ decoder) keep their own mapping. Flutter and JADX messages now embed the clearer ZIP archive is malformed: … text.

Validation

  • tests/boundary/filesystem/artifactZipIntegrity.test.ts: the overlapping, corrupt-member and truncated ZIP cases now assert reason: "format" plus the zip.js detail. These tests previously pinned io. A new case covers an unsupported compression method → unavailable.
  • npm run test:focused on all 52 test files that exercise ZIP/APK/SAZ/JADX/Flutter readers: 557 passed, 3 skipped.
  • npm run check:fast passes.
  • Manual CLI check: ran inspect-artifact on truncated PK\3\4, a bare EOCD signature and a cut-off ZIP before and after the change. identify-flutter-build still reports invalid_format.

Remaining

identify_flutter_build and SAZ decoding still classify every non-limit ZIP failure as malformed input, genuine I/O errors included. They could now use ArtifactReaderFailure.reason, but that changes their error contracts, so it is left for a separate change.

🤖 Generated with Claude Code

zip.js signals archive faults (missing end-of-central-directory record,
unrecognized format, overlapping members, corrupt member data,
unsupported compression) as plain Errors. ZipArtifactReader passed them
through untyped, so the artifact provider's fallback reported every one
as `io` with no detail and told the caller to "check file access".

Type these faults at the ZIP reader boundary: structural and data
corruption become `format` failures and unsupported archive features
become `unavailable`, each carrying the zip.js reason as detail. This
covers enumeration, the getData rejection, and the WritableStream abort
path that delivers corrupt-data errors first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking defect was established.

Summary

The PR turns known ZIP archive faults into ArtifactReaderFailure errors instead of reporting them as file-access failures.

  • ZIP errors now keep their meaning in artifact results.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[ZIP enumeration or extraction fails] --> B{Known ZIP error?}
  B -->|Malformed archive| C[ArtifactReaderFailure: format]
  B -->|Unsupported feature| D[ArtifactReaderFailure: unavailable]
  B -->|No| E[Keep original error]
  C --> F[Artifact operation preserves reason and detail]
  D --> F
  E --> G[Existing error translation]
Loading

Reviews (6) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator Author

Static checks failed on the repo-wide jscpd gate (3.01% at a 3.0% threshold), which origin/main also fails; #2691 restores it. Pushed f-up commit sharing the ZIP inventory failure assertion so this PR's new test no longer adds clones (1481 → 1479 locally).

@morluto
morluto merged commit cd2ad1f into main Oct 13, 2026
6 checks passed
@morluto
morluto deleted the fix/zip-format-failures branch October 13, 2026 12:07
@morluto morluto added bug Something isn't working area: evidence Evidence, artifacts, and reconstruction labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants