From 7b822ddf857db3cdd9ccb52d9e180bcc1b199b92 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Tue, 21 Apr 2020 22:11:23 +0100 Subject: [PATCH] In ZipFile.GetOutputStream, ensure that any created crypto streams are disposed --- src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs index 9a7f64e9f..5efea124f 100644 --- a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs +++ b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs @@ -2621,13 +2621,20 @@ private Stream GetOutputStream(ZipEntry entry) switch (entry.CompressionMethod) { case CompressionMethod.Stored: - result = new UncompressedStream(result); + if (!entry.IsCrypted) + { + // If there is an encryption stream in use, that can be returned directly + // otherwise, wrap the base stream in an UncompressedStream instead of returning it directly + result = new UncompressedStream(result); + } break; case CompressionMethod.Deflated: var dos = new DeflaterOutputStream(result, new Deflater(9, true)) { - IsStreamOwner = false + // If there is an encryption stream in use, then we want that to be disposed when the deflator stream is disposed + // If not, then we don't want it to dispose the base stream + IsStreamOwner = entry.IsCrypted }; result = dos; break;