[PR #939] [MERGED] Fix WinzipAesCryptoStream potentially not getting disposed #1358

Closed
opened 2026-01-29 22:20:09 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/939
Author: @Morilli
Created: 8/21/2025
Status: Merged
Merged: 8/22/2025
Merged by: @adamhathcock

Base: masterHead: fix-winaescryptostream-dispose


📝 Commits (2)

  • 8eea2ce add failing test
  • 9f30696 Adjust logic in CreateDecompressionStream to not wrap the returned stream

📊 Changes

3 files changed (+20 additions, -8 deletions)

View changed files

📝 src/SharpCompress/Common/Zip/ZipFilePart.cs (+3 -8)
📝 tests/SharpCompress.Test/Zip/ZipReaderTests.cs (+17 -0)
tests/TestArchives/Archives/Zip.none.encrypted.zip (+0 -0)

📄 Description

ZipFilePart.CreateDecompressionStream when called with ZipCompressionMethod.None would wrap the passed in stream in a ReadOnlySubstream (if it wasn't one already) and return that. In case of encrypted zip files, that stream was a WinzipAesCryptoStream which needs to be disposed for it to finish reading the entry data, however ReadOnlySubstream never disposes its underlying stream, causing failure when trying to read further.

I've adjusted the logic to never wrap the passed in stream in a ReadOnlySubstream which seems to be fine with the existing logic and ensures the stream is always disposed if necessary. I'm not 100% this is the correct thing to do, but it's really hard to determine who has ownership over which stream and what component should be responsible for disposal, so hopefully unconditionally not wrapping the stream is fine here.

I've added a test to make sure this won't regress in the future.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/939 **Author:** [@Morilli](https://github.com/Morilli) **Created:** 8/21/2025 **Status:** ✅ Merged **Merged:** 8/22/2025 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `master` ← **Head:** `fix-winaescryptostream-dispose` --- ### 📝 Commits (2) - [`8eea2ce`](https://github.com/adamhathcock/sharpcompress/commit/8eea2cef9792dfa9632138371b103b64431f2aa9) add failing test - [`9f30696`](https://github.com/adamhathcock/sharpcompress/commit/9f306966db094738a4dcee014720079fa01494f3) Adjust logic in CreateDecompressionStream to not wrap the returned stream ### 📊 Changes **3 files changed** (+20 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Common/Zip/ZipFilePart.cs` (+3 -8) 📝 `tests/SharpCompress.Test/Zip/ZipReaderTests.cs` (+17 -0) ➕ `tests/TestArchives/Archives/Zip.none.encrypted.zip` (+0 -0) </details> ### 📄 Description - closes #938 `ZipFilePart.CreateDecompressionStream` when called with `ZipCompressionMethod.None` would wrap the passed in stream in a `ReadOnlySubstream` (if it wasn't one already) and return that. In case of encrypted zip files, that stream was a `WinzipAesCryptoStream` which needs to be disposed for it to finish reading the entry data, however `ReadOnlySubstream` never disposes its underlying stream, causing failure when trying to read further. I've adjusted the logic to never wrap the passed in stream in a `ReadOnlySubstream` which seems to be fine with the existing logic and ensures the stream is always disposed if necessary. I'm not 100% this is the correct thing to do, but it's really hard to determine who has ownership over which stream and what component should be responsible for disposal, so hopefully unconditionally not wrapping the stream is fine here. I've added a test to make sure this won't regress in the future. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:20:09 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1358