Skip to content

fix: raw_copy_file wrote two ZIP64 extra fields when the copy needed its own - #1349

Merged
Pr0methean merged 1 commit into
zip-rs:masterfrom
saqib-trywe:fix/raw-copy-duplicate-zip64
Nov 23, 2026
Merged

Pr0methean merged 1 commit into
zip-rs:masterfrom
saqib-trywe:fix/raw-copy-duplicate-zip64

Conversation

@saqib-trywe

@saqib-trywe saqib-trywe commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor
  • The PR title conforms to Conventional Commits and starts with an Angular-convention type.

Fixes #1348.

raw_copy_options copied the source entry's ZIP64 extended information field (0x0001) into the new entry's options as raw bytes. When the copy's sizes or local header offset need ZIP64, the writer adds its own field too, so the entry ends up with two. replace_zip64_extra_field already prevents duplicates among extra_fields.inner, but the copied field arrives through add_extra_field and isn't seen there. ZipArchive then fails on the copy with Invalid local file header. In practice, raw-copying the entries of any archive over 4 GiB produced an unreadable archive.

Fix: skip ExtraField::Zip64ExtendedInformation in raw_copy_options, as the extended timestamp is already skipped. The writer computes the copy's ZIP64 field from its own sizes and offset.

Test: tests/raw_copy_zip64.rs raw-copies an entry whose central header has a ZIP64 field (large_file(true)) into a writer positioned at 4 GiB. The writer is an in-memory Read + Write + Seek that reports the first 4 GiB as zeros without storing them, so the test runs in milliseconds and allocates only a few KB. It checks each copied entry has one ZIP64 field and reads back. It fails on master with Invalid local file header and passes with the fix. I also checked the fix against a real 4.3 GB archive (a stored 4 GiB + 16 MiB entry, then one past the 4 GiB offset): every entry's name, method, CRC, sizes and raw bytes are kept, and the ZIP64 end records are written.

Checks run locally (macOS, stable 1.100.0):

  • cargo fmt --check --all: ok
  • cargo test with default features, --no-default-features and --all-features: 576 / 486 / 636 passed, 0 failed
  • cargo clippy --all-targets with default features and --all-features: clean. With --no-default-features there's one field_reassign_with_default error in src/extra_fields/extra_field.rs:376 that's already on master with this clippy; this PR doesn't touch it.

Maintainer edits are allowed on the branch.


Show it working
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…its own

raw_copy_options copied the source's ZIP64 extended information field
(0x0001) into the new entry's options. When the copy's sizes or offset
need ZIP64, the writer adds its own field too, so the entry had two, and
ZipArchive failed on the result with "Invalid local file header". Skip
the source's field; the writer computes the copy's from its own sizes
and offset.

Fixes zip-rs#1348
@Pr0methean
Pr0methean enabled auto-merge November 23, 2026 03:34
@Pr0methean
Pr0methean added this pull request to the merge queue Nov 23, 2026
Merged via the queue into zip-rs:master with commit fc07c8a Nov 23, 2026
130 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

raw_copy_file writes two ZIP64 extra fields when the copy needs its own, and the archive can't be read back

2 participants