[PR #4006] [CLOSED] fix(artifacts): report ZIP reads beyond the archive as malformed #5986

Closed
opened 2026-10-31 01:10:59 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4006
Author: @jackie-cqz
Created: 10/15/2026
Status: ❌ Closed

Base: main ← Head: fix/3953-zip-read-beyond-eof


📝 Commits (1)

  • 657ba7c fix(artifacts): report ZIP reads beyond the archive as malformed

📊 Changes

2 files changed (+42 additions, -0 deletions)

View changed files

📝 src/artifacts/ZipArtifactReader.test.ts (+34 -0)
📝 src/artifacts/ZipArtifactReader.ts (+8 -0)

📄 Description

Summary

Fixes #3953.

Prepared with AI assistance. A human owner reviews the final diff and owns this
PR, per the Author readiness declarations below.

A malformed ZIP can declare a member offset past the end of the archive. The
ZIP reader clamped the requested length to the remaining bytes, so the clamp
went negative and Buffer.alloc threw an untyped RangeError. That error is
absent from the zip.js failure vocabulary, so the provider classified the whole
operation as file access (io) instead of a malformed archive, and callers saw
file-access guidance for a corrupt input.

Problem and expected behavior

Smallest trigger: inventory an archive whose central directory declares a member
offset beyond the file end.

  • Observed: reason: "io" with no format detail, from an untyped
    RangeError: The value of "size" is out of range ... Received -1024.
  • Controls: a prefix that is not a ZIP at all and an in-file corrupt member both
    already report format.
  • Violated invariant: a malformed archive must be reported as a format fault;
    io is reserved for real file-access failures.

Expected: the malformed archive reports format with a detail naming the
out-of-range read, and valid archives are unaffected.

Change and scope

  • Reject a negative clamped read length with the typed format failure the
    reader already owns, before the read budget check and before allocation.
  • Add a regression fixture whose central directory declares a member offset past
    the archive end.

Why this fits REA's architecture: readUint8Array is the single boundary zip.js
reads through, so the classification is fixed at the producing boundary rather
than repaired in the provider's error mapping. A zero-length read at exactly the
archive end stays allowed, so end-of-archive probes keep working.

Intentionally not included: no change to which archives are accepted, no change
to the provider's failure mapping, and no change to the zip.js failure
vocabulary.

Contract and boundary impact

  • Semantic owner and earliest changed stage: ZipArtifactReader.readUint8Array;
    artifact read stage.
  • Contribution scope fit and linked maintainer decision: not applicable —
    ordinary fix inside existing boundaries.
  • CLI and MCP/tool-catalog contract: none. The failure reason is typed evidence,
    and this corrects it from io to format.
  • Provider, bridge, target-format, or platform compatibility: none; the rule
    applies to every provider that reads ZIP artifacts.
  • Evidence, artifact, provenance, or reconstruction contract: a malformed
    archive now reports format instead of io. Consumers that branch on the
    reason will see the corrected classification.
  • Target selection, authority, upstream behavior, and cleanup details: not
    applicable; only a local file is read.
  • Generated metadata impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: src/artifacts/ZipArtifactReader.test.ts gained a
    "ZipArtifactReader archive bounds" case.
  • Base reproduction: on the base revision the new test fails with
    RangeError { message: 'The value of "size" is out of range. It must be >= 0 && <= 9007199254740991. Received -1024', code: 'ERR_OUT_OF_RANGE' } instead of
    a typed ArtifactReaderFailure. The fixture reaches the bug the same way the
    report did: through the archive's own metadata, not by calling the reader
    internals.
  • User-visible CLI/MCP output: not re-captured at the CLI level; the reader
    failure classification is what the CLI/MCP report, and the boundary suite
    below covers the surrounding inventory behavior.
  • Remaining proof gaps: the original report used a differently constructed
    truncated archive. This change is guarded by the clamped-length invariant, so
    any construction that makes an offset exceed the archive end reaches it, but
    that specific fixture was not re-run.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/artifacts/ZipArtifactReader.test.ts on the base revision — 1 failed with the untyped RangeError above, 6 passed.
  • npm run test:local -- src/artifacts/ZipArtifactReader.test.ts after the fix — 7 passed.
  • npm run test:focused -- tests/boundary/filesystem/artifactZipIntegrity.test.ts — 20 passed, so the existing malformed-archive and unsupported-feature classifications are unchanged.
  • npm run check:fast — typecheck and lint including verify:module-boundaries succeeded, 2/2 tasks.
  • Node v22.23.2 on macOS arm64.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The corrected reason is the one the
    documented contract already assigns to malformed archives.
  • Real Hopper/Ghidra, browser, or OS coverage: none required; no provider or
    browser was launched.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the guard rejects an
    out-of-range read before allocation, so it removes an untyped allocation
    failure path rather than adding one.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4006 **Author:** [@jackie-cqz](https://github.com/jackie-cqz) **Created:** 10/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/3953-zip-read-beyond-eof` --- ### 📝 Commits (1) - [`657ba7c`](https://github.com/morluto/rea/commit/657ba7c793707ab3e348aeedc9a447c937e2a57a) fix(artifacts): report ZIP reads beyond the archive as malformed ### 📊 Changes **2 files changed** (+42 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/artifacts/ZipArtifactReader.test.ts` (+34 -0) 📝 `src/artifacts/ZipArtifactReader.ts` (+8 -0) </details> ### 📄 Description ## Summary Fixes #3953. _Prepared with AI assistance. A human owner reviews the final diff and owns this PR, per the Author readiness declarations below._ A malformed ZIP can declare a member offset past the end of the archive. The ZIP reader clamped the requested length to the remaining bytes, so the clamp went negative and `Buffer.alloc` threw an untyped `RangeError`. That error is absent from the zip.js failure vocabulary, so the provider classified the whole operation as file access (`io`) instead of a malformed archive, and callers saw file-access guidance for a corrupt input. ## Problem and expected behavior Smallest trigger: inventory an archive whose central directory declares a member offset beyond the file end. - Observed: `reason: "io"` with no format detail, from an untyped `RangeError: The value of "size" is out of range ... Received -1024`. - Controls: a prefix that is not a ZIP at all and an in-file corrupt member both already report `format`. - Violated invariant: a malformed archive must be reported as a format fault; `io` is reserved for real file-access failures. Expected: the malformed archive reports `format` with a detail naming the out-of-range read, and valid archives are unaffected. ## Change and scope - Reject a negative clamped read length with the typed `format` failure the reader already owns, before the read budget check and before allocation. - Add a regression fixture whose central directory declares a member offset past the archive end. Why this fits REA's architecture: `readUint8Array` is the single boundary zip.js reads through, so the classification is fixed at the producing boundary rather than repaired in the provider's error mapping. A zero-length read at exactly the archive end stays allowed, so end-of-archive probes keep working. Intentionally not included: no change to which archives are accepted, no change to the provider's failure mapping, and no change to the zip.js failure vocabulary. ## Contract and boundary impact - Semantic owner and earliest changed stage: `ZipArtifactReader.readUint8Array`; artifact read stage. - Contribution scope fit and linked maintainer decision: not applicable — ordinary fix inside existing boundaries. - CLI and MCP/tool-catalog contract: none. The failure reason is typed evidence, and this corrects it from `io` to `format`. - Provider, bridge, target-format, or platform compatibility: none; the rule applies to every provider that reads ZIP artifacts. - Evidence, artifact, provenance, or reconstruction contract: a malformed archive now reports `format` instead of `io`. Consumers that branch on the reason will see the corrected classification. - Target selection, authority, upstream behavior, and cleanup details: not applicable; only a local file is read. - Generated metadata impact: none. Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: `src/artifacts/ZipArtifactReader.test.ts` gained a "ZipArtifactReader archive bounds" case. - Base reproduction: on the base revision the new test fails with `RangeError { message: 'The value of "size" is out of range. It must be >= 0 && <= 9007199254740991. Received -1024', code: 'ERR_OUT_OF_RANGE' }` instead of a typed `ArtifactReaderFailure`. The fixture reaches the bug the same way the report did: through the archive's own metadata, not by calling the reader internals. - User-visible CLI/MCP output: not re-captured at the CLI level; the reader failure classification is what the CLI/MCP report, and the boundary suite below covers the surrounding inventory behavior. - Remaining proof gaps: the original report used a differently constructed truncated archive. This change is guarded by the clamped-length invariant, so any construction that makes an offset exceed the archive end reaches it, but that specific fixture was not re-run. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:local -- src/artifacts/ZipArtifactReader.test.ts` on the base revision — 1 failed with the untyped `RangeError` above, 6 passed. - `npm run test:local -- src/artifacts/ZipArtifactReader.test.ts` after the fix — 7 passed. - `npm run test:focused -- tests/boundary/filesystem/artifactZipIntegrity.test.ts` — 20 passed, so the existing malformed-archive and unsupported-feature classifications are unchanged. - `npm run check:fast` — typecheck and lint including `verify:module-boundaries` succeeded, 2/2 tasks. - Node v22.23.2 on macOS arm64. ## Compatibility, safety, and release - Breaking changes or migration steps: none. The corrected reason is the one the documented contract already assigns to malformed archives. - Real Hopper/Ghidra, browser, or OS coverage: none required; no provider or browser was launched. - Package or release metadata impact: none. - Security, privacy, process, or containment review: the guard rejects an out-of-range read before allocation, so it removes an untyped allocation failure path rather than adding one. ## Author readiness Human owner: <!-- @GitHub-handle --> - [ ] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [ ] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [ ] I declare this PR ready for initial maintainer review. ## Before merge - [ ] This PR addresses a concrete problem or an agreed enhancement. - [ ] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [ ] The PR has one focused outcome and the title follows `type(scope): outcome`. - [ ] Related issue is linked, or the reason for not linking one is stated above. - [ ] Tests cover changed observable behavior and meaningful failure paths. - [ ] Owning docs, contracts, and generated metadata are updated where needed. - [ ] User-visible CLI/MCP changes include representative output. - [ ] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:10:59 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5986
No description provided.