mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
[PR #1162] release to master #1601
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Original Pull Request: https://github.com/adamhathcock/sharpcompress/pull/1162
State: closed
Merged: Yes
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](diffhunk://#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L32-R50))_cacheto use null-forgiving operator (_cache!) and added checks for_isDisposedin methods that access the buffer, throwingObjectDisposedExceptionif accessed after disposal. ([[1]](diffhunk://#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L64-R116),[[2]](diffhunk://#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L109-R139),[[3]](diffhunk://#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L127-R157),[[4]](diffhunk://#diff-e05b040e70e38b0d116d8d268e407131b5ba8b6614af841bc9188cd7f368fee3L150-R180),[[5]](diffhunk://#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](diffhunk://#diff-5203913d939d601de98a07fe1ef8384114c7cbb9de17ccc5a93297b51c301e6eR100-R120))ForwardOnlyStreamwrapper for more accurate stream behavior simulation. ([tests/SharpCompress.Test/Streams/SharpCompressStreamTest.csL67-R75](diffhunk://#diff-5203913d939d601de98a07fe1ef8384114c7cbb9de17ccc5a93297b51c301e6eL67-R75))[tests/SharpCompress.Test/Streams/SharpCompressStreamTest.csR8](diffhunk://#diff-5203913d939d601de98a07fe1ef8384114c7cbb9de17ccc5a93297b51c301e6eR8))Minor codebase cleanups
orig) from theSeekmethod inSharpCompressStream. ([src/SharpCompress/IO/SharpCompressStream.csL258](diffhunk://#diff-d90e17bbeae23cfc33ba23708baa5342f5eb76666ee072503791fee3432a1c04L258))