Skip to content

fix: file-header length check in central directory neglected file comment, and in local header was too stringent by one byte - #1340

Merged
Pr0methean merged 13 commits into
masterfrom
fix_length_off_by_one
Nov 20, 2026
Merged

Pr0methean merged 13 commits into
masterfrom
fix_length_off_by_one

Conversation

@Pr0methean

@Pr0methean Pr0methean commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Autofix with [code]smith
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.

This PR fixes two related issues in start_entry: including the file comment in the local entry length check, and relaxing the boundary condition from >= to >.

The off-by-one fix (> instead of >=) is correct: u16::MAX (65535) bytes is a valid local header size since it still fits in the u16 extra_field_length field.

However, the file comment inclusion in entry_len is incorrect. Per the ZIP specification (APPNOTE 4.3.2), the local file header has no comment field at all — the comment is a central directory-only concept (APPNOTE 4.3.12). Adding file_comment_raw.len() to entry_len artificially limits entries whose local headers would fit fine, solely because they have a long central directory comment. The same issue propagates to the fuzz harness where max_path_len_for is similarly adjusted.

Additional note: The PR title Fix: file length check neglected file comment, but was also too stringent by one byte does not conform to Conventional Commits — the type prefix must be lowercase (fix:, not Fix:), as required by the project's contributing guidelines.


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/write.rs Resolved
Comment thread fuzz/write/src/main.rs Resolved
@Pr0methean Pr0methean changed the title Fix: file length check neglected file comment, but was also too stringent by one byte fix: file length check neglected file comment, but was also too stringent by one byte Nov 20, 2026
@Pr0methean Pr0methean changed the title fix: file length check neglected file comment, but was also too stringent by one byte fix: file-header length check in central directory neglected file comment, and in local header was too stringent by one byte Nov 20, 2026
@Pr0methean
Pr0methean enabled auto-merge November 20, 2026 04:16

@ByGh00st ByGh00st 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 off-by-one fix in start_entry (>= -> >) and the updated tests/zip_extra_field.rs look right (u16::MAX = 65535 fits in a u16 and is strictly less than 64 KiB).

A few issues on the central directory side though: the new extra_field_length + file_comment_length check in write_central_directory_header doesn't include file_name_raw.len() or the 46-byte central header (Magic + ZipCentralEntryBlock), so it sits halfway between enforcing individual u16 field limits and enforcing APPNOTE 4.4.10's 65535-byte combined record limit. Left inline details below, plus a stale comment in fuzz/write/src/main.rs and missing tests for the new check and FileOptions::file_comment().

Comment thread src/write.rs Resolved
Comment thread fuzz/write/src/main.rs Resolved
Comment thread src/write/options.rs Resolved
@Pr0methean
Pr0methean disabled auto-merge November 20, 2026 04:40
@Pr0methean
Pr0methean enabled auto-merge November 20, 2026 05:04
@Pr0methean
Pr0methean added this pull request to the merge queue Nov 20, 2026
Merged via the queue into master with commit 9509531 Nov 20, 2026
129 checks passed
@Pr0methean
Pr0methean deleted the fix_length_off_by_one branch November 20, 2026 06:24
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