Skip to content

fix: by_name().get_metadata() and by_index().get_metadata() now succeed even when compression method is unsupported - #1228

Merged
Pr0methean merged 3 commits into
masterfrom
fix-unsupported
Oct 31, 2026
Merged

Pr0methean merged 3 commits into
masterfrom
fix-unsupported

Conversation

@Pr0methean

@Pr0methean Pr0methean commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@Pr0methean Pr0methean changed the title fix: by_name().get_metadata() and by_index().get_metadata() now succeed even when compression method is unsupported, fix: by_name().get_metadata() and by_index().get_metadata() now succeed even when compression method is unsupported Oct 31, 2026

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this PR correctly address the stated goal of allowing by_name(), by_index(), and by_name_raw() to succeed (returning a ZipFile with accessible metadata) when the archive contains an entry with an unsupported compression method.

Summary of changes:

  1. src/read/readers.rs: Removes the early-return guard in make_crypto_reader that rejected unsupported compression methods before any crypto setup. Since LazyDecompressor is lazy, make_reader now succeeds and the error surfaces only on the first read() call — this is the intended behavior change.
  2. src/read/zip_archive.rs: Adds the new by_name_raw public API method, which delegates to by_index_raw to return the raw compressed bytes without decompression.
  3. tests/unsupported_compression_metadata.rs: New integration test that constructs a valid ZIP, patches the compression method field to an unsupported value (222) in both local and central directory headers at the correct offsets per the ZIP spec (LFH+8, CDFH+10), and asserts that get_metadata() succeeds.

The ZIP field offsets used for patching in the test are correct per the APPNOTE specification. No blocking defects found. The test does not exercise the read-failure path (attempting to decompress with method 222), but that is not the advertised behavior being fixed.

One observation: The test file uses SimpleFileOptions::default() which in a default-features build will apply Deflate compression before the bytes are patched, meaning compressed_size could be either larger or smaller than the plaintext b"content" (7 bytes). The assertion compressed_size > 0 is safe regardless. ✅


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

@Pr0methean
Pr0methean enabled auto-merge October 31, 2026 01:51
@Pr0methean
Pr0methean added this pull request to the merge queue Oct 31, 2026
Merged via the queue into master with commit acd3587 Oct 31, 2026
136 checks passed
@Pr0methean
Pr0methean deleted the fix-unsupported branch October 31, 2026 03:43
codedeviate added a commit to codedeviate/stuffr that referenced this pull request Nov 5, 2026
zip 9.2.0 (zip-rs/zip2#1228) stopped returning
CompressionMethodNotSupported from by_index and read_zipfile_from_stream;
the refusal surfaces on the first read as io::ErrorKind::Unsupported,
which the payload fold turns into exit 5. A reduce entry, a zstd entry on
the pure tier, or shrink/implode from a pipe would read as corrupt.

refuse_undecodable_method restores the open-time refusal (exit 3) on
both rungs for any method zip parses as CompressionMethod::Unsupported.
A no-op on zip 9.1.3, which refused first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant