Skip to content

fix(read): validate EOCD candidates inside ZipIterable::try_new fallback loop - #1347

Merged
Pr0methean merged 3 commits into
zip-rs:masterfrom
ByGh00st:fix/zip-iterable-eocd-fallback
Nov 23, 2026
Merged

Pr0methean merged 3 commits into
zip-rs:masterfrom
ByGh00st:fix/zip-iterable-eocd-fallback

Conversation

@ByGh00st

@ByGh00st ByGh00st commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

ZipIterable::try_new previously broke out of its EOCD candidate loop as soon as CentralDirectoryInfo::try_from(&cde) succeeded, and only checked multi-disk consistency and
umber_of_files > directory_size / 46 afterwards.

When an archive comment contains a fake 22-byte EOCD record aligned with EOF (found by uzz_write_with_no_features on #1343, also reproducible on master), ZipIterable::try_new accepted the stray candidate and failed with Central directory declares more entries than its size allows instead of falling back to the real EOCD like ZipArchive does.

Changes

  • Move the multi-disk and
    umber_of_files > max_entries checks inside the EOCD candidate loop in ZipIterable::try_new so non-abutting bogus candidates fall back to earlier EOCD records while preserving the existing central_directory_abuts_end() stop condition and last_err reporting.
  • Add a regression test ( ake_eocd_in_comment_falls_back_to_real_eocd) in ests/iterable_zip.rs.

Verification

  • cargo test --test iterable_zip (default features and --no-default-features)
  • cargo clippy --all-targets -- -D warnings
  • Replayed the 153-byte AFL crash input from uzz_write_with_no_features against uzz_write (--no-default-features): panicked on master, exits cleanly with this fix.

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

@amazon-q-developer

Copy link
Copy Markdown
Contributor

Warning

Amazon Q Developer for GitHub: end of support

On January 30, 2027, AWS will discontinue support for the Amazon Q Developer for GitHub App. New app installations will no longer be available starting November 18, 2026.

For capabilities similar to the Amazon Q Developer for GitHub App, explore Kiro and the Kiro GitHub App. For more information about the end of support, see Amazon Q Developer end-of-support announcement on the AWS DevOps Blog.

@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 fix is correct and well-structured. Moving the multi-disk and number_of_files > max_entries checks inside the EOCD candidate loop is the right approach — it mirrors how ZipArchive handles the same validation and allows the loop to continue searching for earlier, legitimate EOCD records when a bogus candidate is embedded in the archive comment. The central_directory_abuts_end() stop condition and last_err accumulation are correctly preserved in their new position.

The regression test accurately reproduces the scenario (fake 22-byte EOCD at EOF with comment_length=0 bypassing the abuts_end guard) and validates the fixed behaviour end-to-end without requiring allocation of large buffers. No blocking issues found.


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.

Comment thread src/read/zip_iterable.rs Outdated
let candidate = CentralDirectoryInfo::try_from(&cde).and_then(|info| {
if info.disk_number != info.disk_with_central_directory {
return Err(ZipError::UnsupportedArchive(
"Support for multi-disk files is not implemented",

@Pr0methean Pr0methean Nov 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keep this check separate. Otherwise ZIP cloaking is possible if one of the EOCDs declares the archive to be multi-disk and the other doesn't.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed in ea7231b3. Moved the multi-disk check back outside the fallback loop and added a dual-EOCD regression test (multidisk_zip64_eocd_does_not_fall_back_to_earlier_eocd) verifying a trailing multi-disk ZIP64 EOCD hard-fails with UnsupportedArchive instead of falling back to an earlier single-disk EOCD.

Side note: ZipArchive::get_metadata currently hits the same check inside read_central_header within its EOCD fallback loop (src/read/zip_archive.rs:339), so a non-abutting multi-disk ZIP64 EOCD can still fall back there too. Happy to tighten that in a separate PR if you want.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Side note: ZipArchive::get_metadata currently hits the same check inside read_central_header within its EOCD fallback loop (src/read/zip_archive.rs:339), so a non-abutting multi-disk ZIP64 EOCD can still fall back there too. Happy to tighten that in a separate PR if you want.

Yes please.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Opened #1350 with the fix and a dual-EOCD regression test for ZipArchive.

Pr0methean
Pr0methean previously approved these changes Nov 23, 2026
@Pr0methean
Pr0methean enabled auto-merge November 23, 2026 03:32
@ByGh00st

Copy link
Copy Markdown
Contributor Author

Also pushed 9296f756 to bound max_entries by eocd_pos - directory_start as well as the declared directory_size: a fake EOCD in a comment with an inflated central_directory_size (e.g. 0xFFFF_FFFF) and small number_of_files (e.g. 10) previously bypassed directory_size / 46 even when fewer than 10 * 46 bytes existed before the EOCD. Added fake_eocd_in_comment_with_inflated_cd_size_falls_back_to_real_eocd to cover it.

@Pr0methean
Pr0methean added this pull request to the merge queue Nov 23, 2026
Merged via the queue into zip-rs:master with commit 8bf228e 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.

2 participants