Skip to content

Zip async correctness fix#129122

Merged
alinpahontu2912 merged 3 commits into
dotnet:mainfrom
alinpahontu2912:alin/zip-async-correctness-fix
Jun 9, 2026
Merged

Zip async correctness fix#129122
alinpahontu2912 merged 3 commits into
dotnet:mainfrom
alinpahontu2912:alin/zip-async-correctness-fix

Conversation

@alinpahontu2912

Copy link
Copy Markdown
Member

fix mix of sync/async reads when reading zip comment

alinpahontu2912 and others added 2 commits June 8, 2026 13:16
…path

ZipEndOfCentralDirectoryBlock.ReadBlockAsync called the synchronous Stream.ReadExactly when copying the archive comment after the EOCD header. This blocks the calling thread on the underlying stream and silently ignores the supplied CancellationToken. Switch to ReadExactlyAsync with ConfigureAwait(false), matching the rest of the async path.

Adds a regression test using CallTrackingStream to verify the async open path never invokes the synchronous Stream.Read or ReadByte when reading an archive with a non-empty comment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@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.

Pull request overview

Fixes async ZIP reading correctness by ensuring the archive comment is read asynchronously (avoiding synchronous Stream.Read* calls) on the async code path, and adds a regression test to validate the behavior.

Changes:

  • Switch ZipEndOfCentralDirectoryBlock.ReadBlockAsync to use ReadExactlyAsync(..., cancellationToken) when reading the archive-level comment.
  • Add a unit test that asserts ZipArchive.CreateAsync(...) + ZipArchive.Comment does not invoke synchronous Stream.Read / Stream.ReadByte on the provided stream.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.Async.cs Replaces a synchronous ReadExactly with await ReadExactlyAsync(..., cancellationToken) to keep the async path fully async.
src/libraries/System.IO.Compression/tests/ZipArchive/zip_ReadTests.cs Adds a regression test using CallTrackingStream to ensure async ZIP open + comment retrieval doesn’t call sync read APIs.

Comment thread src/libraries/System.IO.Compression/tests/ZipArchive/zip_ReadTests.cs Outdated
Comment thread src/libraries/System.IO.Compression/tests/ZipArchive/zip_ReadTests.cs Outdated
@alinpahontu2912 alinpahontu2912 enabled auto-merge (squash) June 9, 2026 13:18
@alinpahontu2912 alinpahontu2912 merged commit 9593745 into dotnet:main Jun 9, 2026
95 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.

4 participants