[PR #1113] Fix a usage of ReadOnly that use dispose in 7Zip #1543

Open
opened 2026-01-29 22:21:04 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/adamhathcock/sharpcompress/pull/1113

State: closed
Merged: Yes


Maybe addresses https://github.com/adamhathcock/sharpcompress/issues/1105
This pull request improves stream disposal behavior and consistency across several stream types in the SharpCompress library, refactors the implementation of stream skipping utilities, and adds comprehensive tests to verify correct disposal semantics. The main changes are grouped below.

Stream disposal and leaveOpen support improvements:

  • Updated ReadOnlySubStream constructors to accept a leaveOpen parameter, ensuring the inner stream is disposed correctly based on this flag.
  • Modified SevenZipFilePart.GetCompressedStream() to explicitly set leaveOpen: false when creating a ReadOnlySubStream, ensuring proper disposal of the underlying stream.
  • Refactored LZipStream to store a reference to the original stream and updated its Dispose method to dispose the original stream only in compression mode, improving disposal correctness. [1] [2]

Stream skipping utilities refactor:

  • Simplified Stream.Skip, Stream.SkipAsync, and related methods in Utility.cs to use ReadOnlySubStream and Stream.Null, reducing buffer management complexity and improving maintainability.

Testing and verification:

  • Added a new DisposalTests suite to verify the disposal behavior of various stream implementations, including checks for correct handling of the leaveOpen parameter and always/never disposal patterns.

Minor cleanup:

  • Removed the unused IsRecording property from SharpCompressStream, streamlining the codebase.
**Original Pull Request:** https://github.com/adamhathcock/sharpcompress/pull/1113 **State:** closed **Merged:** Yes --- Maybe addresses https://github.com/adamhathcock/sharpcompress/issues/1105 This pull request improves stream disposal behavior and consistency across several stream types in the SharpCompress library, refactors the implementation of stream skipping utilities, and adds comprehensive tests to verify correct disposal semantics. The main changes are grouped below. **Stream disposal and leaveOpen support improvements:** * Updated `ReadOnlySubStream` constructors to accept a `leaveOpen` parameter, ensuring the inner stream is disposed correctly based on this flag. * Modified `SevenZipFilePart.GetCompressedStream()` to explicitly set `leaveOpen: false` when creating a `ReadOnlySubStream`, ensuring proper disposal of the underlying stream. * Refactored `LZipStream` to store a reference to the original stream and updated its `Dispose` method to dispose the original stream only in compression mode, improving disposal correctness. [[1]](diffhunk://#diff-44b45464653f8440fd0885412f8b8b22fdc507753278d389bd5b3b6b05a7a32cR48-R53) [[2]](diffhunk://#diff-44b45464653f8440fd0885412f8b8b22fdc507753278d389bd5b3b6b05a7a32cR130-R133) **Stream skipping utilities refactor:** * Simplified `Stream.Skip`, `Stream.SkipAsync`, and related methods in `Utility.cs` to use `ReadOnlySubStream` and `Stream.Null`, reducing buffer management complexity and improving maintainability. **Testing and verification:** * Added a new `DisposalTests` suite to verify the disposal behavior of various stream implementations, including checks for correct handling of the `leaveOpen` parameter and always/never disposal patterns. **Minor cleanup:** * Removed the unused `IsRecording` property from `SharpCompressStream`, streamlining the codebase.
claunia added the pull-request label 2026-01-29 22:21:04 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1543