Merge pull request #1156 from adamhathcock/copilot/fix-sharpcompress-…#1157
Merged
adamhathcock merged 2 commits intoreleasefrom Jan 25, 2026
Merged
Merge pull request #1156 from adamhathcock/copilot/fix-sharpcompress-…#1157adamhathcock merged 2 commits intoreleasefrom
adamhathcock merged 2 commits intoreleasefrom
Conversation
…archive-iteration Fix silent iteration failure when input stream throws on Flush() # Conflicts: # src/SharpCompress/packages.lock.json
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression where archive iteration over certain ZIPs would silently stop after the first entry when the underlying input stream throws NotSupportedException from Flush(), and adjusts the earlier workaround to a more robust, stream-mode-aware fix. It also adds focused regression tests and a test helper stream to ensure this behavior remains stable in both sync and async code paths.
Changes:
- Add
ThrowOnFlushStreamtest helper that throws onFlush/FlushAsyncto simulate non-flushable forward-only input streams. - Update
ZlibBaseStream.FlushandFlushAsyncto only flush the underlying stream when in writer mode, avoiding meaningless and potentially failing flushes on input streams during reads. - Simplify
EntryStream.Dispose/DisposeAsyncby removing localNotSupportedExceptionsuppression around Deflate/LZMAFlushcalls, now that those flush implementations are safe in read scenarios, and add sync/async regression tests to verify iteration does not break for Deflate and LZMA archives.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
tests/SharpCompress.Test/Zip/ZipReaderTests.cs |
Adds synchronous regression tests ensuring archive iteration over Deflate and LZMA ZIPs continues past the first entry even when the underlying stream throws on Flush(). |
tests/SharpCompress.Test/Zip/ZipReaderAsyncTests.cs |
Adds corresponding async regression tests using ReaderFactory.OpenAsyncReader, validating the same behavior for async iteration. |
tests/SharpCompress.Test/Mocks/ThrowOnFlushStream.cs |
Introduces a mock stream that throws on Flush/FlushAsync while delegating read operations, used to simulate problematic input streams in the new tests. |
src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs |
Changes Flush/FlushAsync to guard the underlying stream flush by _streamMode == StreamMode.Writer, preventing NotSupportedException from read-side Flush calls while preserving writer behavior and internal buffer rewind logic. |
src/SharpCompress/Common/EntryStream.cs |
Removes local try/catch (NotSupportedException) around Deflate/LZMA Flush/FlushAsync calls during dispose, relying on the updated compressor flush behavior while keeping the over-read rewind logic intact. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jan 26, 2026
This was referenced Feb 2, 2026
This was referenced Feb 11, 2026
This was referenced Feb 16, 2026
This was referenced Feb 23, 2026
This was referenced Mar 4, 2026
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.
…archive-iteration
Fix silent iteration failure when input stream throws on Flush() # Conflicts:
src/SharpCompress/packages.lock.json
Reverts changes from the last release to be a more real fix