Merged
Conversation
…meter-lzipstream Add leaveOpen parameter to LZipStream and BZip2Stream
Merge pull request #1145 from adamhathcock/copilot/add-leaveopen-para…
…ush-issue Fix EntryStream.Dispose() throwing NotSupportedException on non-seekable streams
Adam/1151 release cherry pick
…archive-iteration Fix silent iteration failure when input stream throws on Flush() # Conflicts: # src/SharpCompress/packages.lock.json
Merge pull request #1156 from adamhathcock/copilot/fix-sharpcompress-…
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Fix ArrayPool corruption from double-disposal in BufferedSubStream
add check to see if we need to seek before hand
…ster # Conflicts: # src/SharpCompress/IO/BufferedSubStream.cs # tests/SharpCompress.Test/Zip/ZipReaderAsyncTests.cs # tests/SharpCompress.Test/Zip/ZipReaderTests.cs
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request improves the safety and robustness of the BufferedSubStream implementation by adding double disposal protection, optimizing sequential reads, and adding tests to verify the changes.
Changes:
- Added
_isDisposedflag and buffer nullification to prevent double disposal and ArrayPool corruption - Optimized sequential reads by avoiding unnecessary seek operations on seekable streams
- Added test coverage for double disposal scenario and updated existing test to use ForwardOnlyStream
- Removed unused variable from SharpCompressStream
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/SharpCompress/IO/BufferedSubStream.cs | Added disposal guard, made cache nullable, optimized seek behavior for sequential reads, and increased buffer size from 32KB to 80KB |
| tests/SharpCompress.Test/Streams/SharpCompressStreamTest.cs | Added double disposal test and updated existing test to use ForwardOnlyStream wrapper |
| src/SharpCompress/IO/SharpCompressStream.cs | Removed unused orig variable from Seek method |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Feb 11, 2026
This was referenced Feb 13, 2026
Closed
This was referenced Feb 23, 2026
Closed
This was referenced Mar 2, 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.
This pull request improves the safety and robustness of the
BufferedSubStreamimplementation inSharpCompress, particularly around resource management and stream disposal. The changes ensure that the underlying buffer is managed correctly, prevent double disposal issues, and add a new test to verify this behavior. Additionally, minor code improvements and test enhancements are included.Resource management and disposal safety
_isDisposedflag toBufferedSubStreamto prevent double disposal and ensure the buffer is only returned to the pool once, avoiding pool corruption. The buffer (_cache) is now set tonullafter being returned. ([src/SharpCompress/IO/BufferedSubStream.csL32-R50](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L32-R50))_cacheto use null-forgiving operator (_cache!) and added checks for_isDisposedin methods that access the buffer, throwingObjectDisposedExceptionif accessed after disposal. ([[1]](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L64-R116),[[2]](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L109-R139),[[3]](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L127-R157),[[4]](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L150-R180),[[5]](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L177-R207))Test improvements
BufferedSubStream_DoubleDispose_DoesNotCorruptArrayPoolto verify that double disposal does not corrupt the array pool or throw exceptions. ([tests/SharpCompress.Test/Streams/SharpCompressStreamTest.csR100-R120](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-5203913d939d601de98a07fe1ef8384114c7cbb9de17ccc5a93297b51c301e6eR100-R120))ForwardOnlyStreamwrapper for more accurate stream behavior simulation. ([tests/SharpCompress.Test/Streams/SharpCompressStreamTest.csL67-R75](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-5203913d939d601de98a07fe1ef8384114c7cbb9de17ccc5a93297b51c301e6eL67-R75))[tests/SharpCompress.Test/Streams/SharpCompressStreamTest.csR8](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-5203913d939d601de98a07fe1ef8384114c7cbb9de17ccc5a93297b51c301e6eR8))Minor codebase cleanups
orig) from theSeekmethod inSharpCompressStream. ([src/SharpCompress/IO/SharpCompressStream.csL258](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-d90e17bbeae23cfc33ba23708baa5342f5eb76666ee072503791fee3432a1c04L258))