Skip to content

Return EOF when reading past the end of a memory archive - #394

Open
rodrigouroz wants to merge 1 commit into
weichsel:developmentfrom
rodrigouroz:codex/memory-file-eof
Open

rodrigouroz wants to merge 1 commit into
weichsel:developmentfrom
rodrigouroz:codex/memory-file-eof

Conversation

@rodrigouroz

Copy link
Copy Markdown

Changes proposed in this PR

Reading a memory-backed archive whose local-file-header offset points past the end of its data currently traps while constructing a range in MemoryFile.readData. Return zero bytes at or beyond EOF before computing that range, matching the file-backed reader's behavior.

Add regression tests for EOF reads on empty, ordinary, and sliced Data, preserving the file position and allowing a seek back to valid data. Also exercise a malformed local-header offset through Archive(data:accessMode:) and register both tests in the Linux test list.

Tests performed

  • Both new tests terminate with signal 5 on the base revision and pass with the fix.
  • Full release suite: 133 tests passed on macOS 27.0, Xcode 27.0, Swift 6.4.
  • Line coverage remains 100% (2,320/2,320), using the CI coverage exclusions. Archive+MemoryFile.swift also has 100% line coverage.
  • SwiftLint 0.65.1: no violations across all 50 tracked Swift files.
  • A standalone consumer reproducing VoxKey's malformed ZIP import now completes without a crash; valid ZIP contents remain readable.
  • git diff --check passes. Linux was not run locally.

Further info for the reviewer

This came from VoxKey's vocabulary archive import, which currently uses a temporary file to avoid this memory-reader trap.

Seeking past EOF remains permitted, including for existing write behavior. Invalid archive entries still terminate iteration as before; this change does not add archive validation or change the public API. Two blank lines were removed from the test registry file to keep it within the existing 400-line SwiftLint limit.

Prepared with AI assistance; the regression and consumer checks above were run locally.

Open Issues

No matching open issue was found. Base revision: e7a17d57c583067eaa6659cd6d9521265b7664e9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant