Fix ZipArchive Update mode rewriting unchanged archives on Dispose#123719
Open
alinpahontu2912 wants to merge 8 commits intodotnet:mainfrom
Open
Fix ZipArchive Update mode rewriting unchanged archives on Dispose#123719alinpahontu2912 wants to merge 8 commits intodotnet:mainfrom
alinpahontu2912 wants to merge 8 commits intodotnet:mainfrom
Conversation
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/area-system-io-compression |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression where opening entry streams in ZipArchiveMode.Update could mark the archive as modified even when no data was written, causing unnecessary rewrites on Dispose (and failures on non-expandable streams).
Changes:
- Track actual writes in Update mode by notifying the entry only on the first write to the opened stream.
- Skip rewriting Update-mode archives on
Disposeunless the archive is actually modified (while still writing newly-created empty archives). - Add regression tests covering Package/Zip scenarios where entries are read without writes.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.IO.Packaging/tests/Tests.cs | Adds regression test ensuring Package.Open(ReadWrite) doesn’t throw on Dispose when only reading. |
| src/libraries/System.IO.Compression/tests/ZipArchive/zip_UpdateTests.cs | Updates/extends Update-mode tests and adds regression tests for non-expandable streams. |
| src/libraries/System.IO.Compression/src/System/IO/Compression/ZipCustomStreams.cs | Adds write-notification plumbing to mark entries modified only when written. |
| src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs | Stops marking entries modified on open; introduces MarkAsModified; adjusts write path to reuse original compressed bytes if unchanged. |
| src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.Async.cs | Async equivalents of Update-mode changes and unchanged-data handling. |
| src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchive.cs | Adds Update-mode “write only if modified” behavior and “new archive” detection. |
| src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchive.Async.cs | Async equivalents of Update-mode “write only if modified” and “new archive” detection. |
src/libraries/System.IO.Compression/tests/ZipArchive/zip_UpdateTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.Async.cs
Show resolved
Hide resolved
stephentoub
reviewed
Jan 28, 2026
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchive.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Jan 28, 2026
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchive.cs
Show resolved
Hide resolved
This was referenced Jan 29, 2026
Open
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchive.cs
Show resolved
Hide resolved
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchive.Async.cs
Show resolved
Hide resolved
src/libraries/System.IO.Compression/tests/ZipArchive/zip_InvalidParametersAndStrangeFiles.cs
Show resolved
Hide resolved
This was referenced Jan 30, 2026
rzikm
reviewed
Feb 2, 2026
src/libraries/System.IO.Compression/tests/ZipArchive/zip_UpdateTests.cs
Outdated
Show resolved
Hide resolved
rzikm
reviewed
Feb 2, 2026
src/libraries/System.IO.Compression/tests/ZipArchive/zip_UpdateTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/tests/ZipArchive/zip_UpdateTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Compression/tests/ZipArchive/zip_InvalidParametersAndStrangeFiles.cs
Show resolved
Hide resolved
rzikm
approved these changes
Feb 3, 2026
src/libraries/System.IO.Compression/tests/ZipArchive/zip_UpdateTests.cs
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix ZipArchive in Update mode rewriting when no changes made
Opening an entry stream in ZipArchiveMode.Update would immediately mark the archive as modified, causing Dispose to attempt a rewrite even when no actual writes occurred. This threw NotSupportedException on non-expandable streams like fixed-size MemoryStream.
The fix tracks actual writes via WrappedStream and only marks the entry as modified when data is written. Archives created on empty streams are marked as new to ensure they're still written on first creation.
Fixes #123419