Skip to content

Deduplicate ZipArchive sync/async implementation using IReadWriteAdapter - #134179

Draft
iremyux wants to merge 12 commits into
dotnet:mainfrom
iremyux:127380-deduplicate-ziparchive
Draft

iremyux wants to merge 12 commits into
dotnet:mainfrom
iremyux:127380-deduplicate-ziparchive

Conversation

@iremyux

@iremyux iremyux commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

This is the ZIP counterpart to #129282, which deduplicated the sync/async implementations of TarReader/TarWriter using the IReadWriteAdapter pattern. This PR applies the same approach to System.IO.Compression's ZIP implementation, merging each sync/async method pair.

Fixes #127380

@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.

@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.

🟡 Changes recommended

Encrypted Update-mode operations regress password-error recovery and write-only replacement when the original AES salt is unavailable.

2 open findings
What changed in this PR

Applies the TAR adapter pattern from #129282 to ZIP, sharing synchronous and asynchronous implementations to address #127380.

Changes:

  • Introduces shared adapter-based archive, entry, and ZIP block operations.
  • Removes duplicated async implementations.
  • Updates project references to include ReadWriteAdapter.

Builds and tests were not run.

File Description
src/​libraries/​System.IO.Compression/​src/​System/​IO/​Compression/​ZipHelper.cs Shares signature-search logic.
src/​libraries/​System.IO.Compression/​src/​System/​IO/​Compression/​ZipHelper.Async.cs Removes duplicate async helpers.
src/​libraries/​System.IO.Compression/​src/​System/​IO/​Compression/​ZipBlocks.cs Shares ZIP block reading and writing.
src/​libraries/​System.IO.Compression/​src/​System/​IO/​Compression/​ZipBlocks.Async.cs Removes duplicate async block operations.
src/​libraries/​System.IO.Compression/​src/​System/​IO/​Compression/​ZipArchiveEntry.cs Consolidates entry operations and stream lifecycle handling.
src/​libraries/​System.IO.Compression/​src/​System/​IO/​Compression/​ZipArchiveEntry.Async.cs Removes separate async entry implementation.
src/​libraries/​System.IO.Compression/​src/​System/​IO/​Compression/​ZipArchive.cs Shares directory parsing and archive finalization.
src/​libraries/​System.IO.Compression/​src/​System/​IO/​Compression/​ZipArchive.Async.cs Retains async entry points; removes duplicated internals.
src/​libraries/​System.IO.Compression/​src/​System.IO.Compression.csproj Includes the adapter and removes deleted sources.

🧠 Review effort: Balanced

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.

🔵 Needs a closer look

Cancellation during encrypted-header reading leaves the entry marked open for writing, blocking retries.

0 open findings

2 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Cancellation during encrypted header read blocks Update-mode retry

src/​libraries/​System.IO.Compression/​src/​System/​IO/​Compression/​ZipArchiveEntry.cs:879

In Update mode, cancellation while the AES or ZipCrypto factory reads the encryption header now leaves _currentlyOpenForWrite set and _storedUncompressedData allocated. OperationCanceledException bypasses this cleanup, so retrying with a fresh token throws UpdateModeOneStream. Previously, the encrypted async path acquired the decryption stream before setting this state. Run this rollback for all acquisition/copy failures and rethrow the original exception. Add a regression test that cancels during the encryption-header read and then successfully retries.

🧠 Review effort: Balanced

Co-authored-by: Copilot <[email protected]>

Copilot-Session: a0129538-9787-4ce3-aa36-47a333fc2e03

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.

🟡 Changes recommended

The retry test uses an incorrect fixture password, and asynchronous Update-mode reads allocate the full entry buffer before password rejection, risking excessive memory use or OutOfMemoryException.

2 open issues

Review effort: Balanced


async ValueTask<MemoryStream> GetUncompressedDataCoreAsync(ValueTask<Stream> streamTask, bool readOriginalData, CancellationToken token)
{
_storedUncompressedData = new MemoryStream((int)_uncompressedSize);

await Assert.ThrowsAsync<InvalidDataException>(() => OpenEntryStream(async, entry, "PLACEHOLDER"));

using (Stream goodbyeStream = await OpenEntryStream(async, entry, "S3cur3P@ssw0rd1"))

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.IO.Compression linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deduplicate ZipArchive sync/async implementation

2 participants