Skip to content

Commit

Permalink
PR #452: Ensure crypto streams are disposed in ZipFile.GetOutputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Numpsy committed Aug 16, 2020
1 parent a6cdf09 commit 8eb94b1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2618,13 +2618,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;
Expand Down

0 comments on commit 8eb94b1

Please sign in to comment.