Skip to content

Conversation

@Morilli
Copy link
Contributor

@Morilli Morilli commented Aug 21, 2025

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.

…ream

a ReadOnlySubStream never disposes its passes in stream which is problematic when that stream needs to be disposed. It's hard to tell who exactly has ownership over which stream here, but I'll just assume that whatever stream is passed in here should be disposed.
@Morilli Morilli force-pushed the fix-winaescryptostream-dispose branch from d57336c to 9f30696 Compare August 21, 2025 18:09
Copy link
Owner

@adamhathcock adamhathcock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems right. Must have been something before that needed this. Oh well. Thanks!

@adamhathcock adamhathcock merged commit d23560a into adamhathcock:master Aug 22, 2025
2 checks passed
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.

ExtractToDirectory has missing files when working with encrypted zip files which contain directories

2 participants