Skip to content

Merge pull request #1156 from adamhathcock/copilot/fix-sharpcompress-…#1157

Merged
adamhathcock merged 2 commits intoreleasefrom
adam/1154-release
Jan 25, 2026
Merged

Merge pull request #1156 from adamhathcock/copilot/fix-sharpcompress-…#1157
adamhathcock merged 2 commits intoreleasefrom
adam/1154-release

Conversation

@adamhathcock
Copy link
Owner

…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

…archive-iteration

Fix silent iteration failure when input stream throws on Flush()
# Conflicts:
#	src/SharpCompress/packages.lock.json
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ThrowOnFlushStream test helper that throws on Flush/FlushAsync to simulate non-flushable forward-only input streams.
  • Update ZlibBaseStream.Flush and FlushAsync to only flush the underlying stream when in writer mode, avoiding meaningless and potentially failing flushes on input streams during reads.
  • Simplify EntryStream.Dispose / DisposeAsync by removing local NotSupportedException suppression around Deflate/LZMA Flush calls, 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.

@adamhathcock adamhathcock merged commit 4ca1a77 into release Jan 25, 2026
2 checks passed
@adamhathcock adamhathcock deleted the adam/1154-release branch January 25, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants