Repository navigation
fix(read): validate EOCD candidates inside ZipIterable::try_new fallback loop - #1347
Conversation
|
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. |
There was a problem hiding this comment.
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.
| 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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Side note:
ZipArchive::get_metadatacurrently hits the same check insideread_central_headerwithin 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.
There was a problem hiding this comment.
Opened #1350 with the fix and a dual-EOCD regression test for ZipArchive.
|
Also pushed |
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
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.
Verification
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.