Skip to content

Add missing check for corrupted central directory - #131257

Merged
alinpahontu2912 merged 1 commit into
dotnet:mainfrom
alinpahontu2912:fuzzer_fix
Jul 23, 2026
Merged

Add missing check for corrupted central directory#131257
alinpahontu2912 merged 1 commit into
dotnet:mainfrom
alinpahontu2912:fuzzer_fix

Conversation

@alinpahontu2912

Copy link
Copy Markdown
Member

Fixes #131228

@alinpahontu2912
alinpahontu2912 requested review from a team and MihaZupan July 23, 2026 11:26
@alinpahontu2912 alinpahontu2912 self-assigned this Jul 23, 2026
Copilot AI review requested due to automatic review settings July 23, 2026 11:26
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI 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.

Pull request overview

This PR hardens System.IO.Compression ZIP reading for AES-encrypted entries by avoiding an unexpected ArgumentOutOfRangeException when a corrupted central directory points a local-header offset past the end of the archive. Instead of failing during central directory parsing (when salts are eagerly read), the error is deferred until the entry is opened, aligning AES behavior with non-encrypted entries.

Changes:

  • Add an early “offset past end-of-stream” guard in AES salt pre-read logic (sync + async) to avoid Seek throwing on some stream types (e.g., MemoryStream).
  • Add a regression test that corrupts a central directory record’s local header offset and verifies enumeration doesn’t throw unexpectedly, while Open() still fails with InvalidDataException.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/libraries/System.IO.Compression/tests/ZipArchive/zip_InvalidParametersAndStrangeFiles.cs Adds a regression test ensuring central directory parsing doesn’t throw unexpectedly for a corrupted AES entry offset and that failure is deferred to entry open.
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs Adds a length-based guard in ReadEncryptionSaltIfNeeded to prevent Seek-triggered ArgumentOutOfRangeException during central directory parsing.
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.Async.cs Mirrors the same guard for the async salt pre-read path.

@rzikm rzikm left a comment

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.

LGTM, I assume you ran the fuzzer locally to confirm there aren't other bugs still lurking?

@alinpahontu2912

alinpahontu2912 commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

Yep, I ran it locally and it worked. Also ran it against the faulty input directly

@MihaZupan

Copy link
Copy Markdown
Member

Thank you.
Let me see if this command still works:
@MihuBot fuzz ZipArchive

@MihuBot

MihuBot commented Jul 23, 2026

Copy link
Copy Markdown

Ran the fuzzer(s) successfully. Code coverage reports:

@alinpahontu2912

Copy link
Copy Markdown
Member Author

/ba-g failures are unrelated to my change

@alinpahontu2912
alinpahontu2912 merged commit 03fc461 into dotnet:main Jul 23, 2026
82 of 86 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 24, 2026
hez2010 pushed a commit to hez2010/runtime that referenced this pull request Jul 26, 2026
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.

[ZipArchiveFuzzer]: ArgumentOutOfRangeException in ReadEncryptionSaltIfNeeded

6 participants