Skip to content

release to master#1162

Merged
adamhathcock merged 18 commits intomasterfrom
adam/release-to-master
Jan 26, 2026
Merged

release to master#1162
adamhathcock merged 18 commits intomasterfrom
adam/release-to-master

Conversation

@adamhathcock
Copy link
Owner

This pull request improves the safety and robustness of the BufferedSubStream implementation in SharpCompress, 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

  • Added an _isDisposed flag to BufferedSubStream to prevent double disposal and ensure the buffer is only returned to the pool once, avoiding pool corruption. The buffer (_cache) is now set to null after being returned. ([src/SharpCompress/IO/BufferedSubStream.csL32-R50](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L32-R50))
  • Updated all usages of _cache to use null-forgiving operator (_cache!) and added checks for _isDisposed in methods that access the buffer, throwing ObjectDisposedException if 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

  • Added a new unit test BufferedSubStream_DoubleDispose_DoesNotCorruptArrayPool to 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))
  • Modified the existing test to use a ForwardOnlyStream wrapper for more accurate stream behavior simulation. ([tests/SharpCompress.Test/Streams/SharpCompressStreamTest.csL67-R75](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-5203913d939d601de98a07fe1ef8384114c7cbb9de17ccc5a93297b51c301e6eL67-R75))
  • Added missing test mock import for completeness. ([tests/SharpCompress.Test/Streams/SharpCompressStreamTest.csR8](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-5203913d939d601de98a07fe1ef8384114c7cbb9de17ccc5a93297b51c301e6eR8))

Minor codebase cleanups

  • Removed an unused variable (orig) from the Seek method in SharpCompressStream. ([src/SharpCompress/IO/SharpCompressStream.csL258](https://github.com/adamhathcock/sharpcompress/pull/1162/files#diff-d90e17bbeae23cfc33ba23708baa5342f5eb76666ee072503791fee3432a1c04L258))

adamhathcock and others added 18 commits January 19, 2026 09:58
…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
…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
Copilot AI review requested due to automatic review settings January 26, 2026 13:25
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 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 _isDisposed flag 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.

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.

3 participants