Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In ZipFile.GetOutputStream, ensure that any created crypto streams are disposed #452

Merged
merged 1 commit into from
Aug 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down