Skip to content

Improve ZipArchive diagnostics for empty and invalid streams - #137247

Merged
iremyux merged 2 commits into
dotnet:mainfrom
iremyux:136215-ziparchive-error-messages
Nov 13, 2026
Merged

iremyux merged 2 commits into
dotnet:mainfrom
iremyux:136215-ziparchive-error-messages

Conversation

@iremyux

@iremyux iremyux commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Report distinct errors for empty streams and missing End of Central Directory records in synchronous and asynchronous ZIP readers.

Fixes #136215

@azure-pipelines

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

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.

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.

🟢 Approval recommended

No active review issues are reported for the ZIP stream-validation and diagnostic changes.

No open issues 🎉

What changed in this PR

Improves ZipArchive diagnostics for empty and invalid input streams, addressing the confusing error messages described in #136215.

Changes:

  • Adds shared stream-length validation to synchronous and asynchronous ZIP readers.
  • Introduces a dedicated empty-stream message and clarifies the missing End of Central Directory message.
  • Adds regression tests for invalid inputs, empty archive creation, and prefixed archives.
File Description
src/​libraries/​System.IO.Compression/​tests/​ZipArchive/​zip_InvalidParametersAndStrangeFiles.cs Tests diagnostics and valid archive scenarios across synchronous and asynchronous paths.
src/​libraries/​System.IO.Compression/​tests/​System.IO.Compression.Tests.csproj Makes library string resources available to test assertions.
src/​libraries/​System.IO.Compression/​src/​System/​IO/​Compression/​ZipArchive.cs Validates stream length before locating the End of Central Directory.
src/​libraries/​System.IO.Compression/​src/​System/​IO/​Compression/​ZipArchive.Async.cs Applies the same validation to asynchronous reading.
src/​libraries/​System.IO.Compression/​src/​Resources/​Strings.resx Adds and clarifies diagnostic messages.

Review effort: Balanced

@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, Thanks!

@iremyux
iremyux merged commit c5b176e into dotnet:main Nov 13, 2026
89 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 13, 2026
@iremyux
iremyux deleted the 136215-ziparchive-error-messages branch November 16, 2026 13: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.

ZipArchive should report better error message for empty or invalid stream

3 participants