Skip to content

Commit 8eb94b1

Browse files
authored
PR #452: Ensure crypto streams are disposed in ZipFile.GetOutputStream
1 parent a6cdf09 commit 8eb94b1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -2618,13 +2618,20 @@ private Stream GetOutputStream(ZipEntry entry)
26182618
switch (entry.CompressionMethod)
26192619
{
26202620
case CompressionMethod.Stored:
2621-
result = new UncompressedStream(result);
2621+
if (!entry.IsCrypted)
2622+
{
2623+
// If there is an encryption stream in use, that can be returned directly
2624+
// otherwise, wrap the base stream in an UncompressedStream instead of returning it directly
2625+
result = new UncompressedStream(result);
2626+
}
26222627
break;
26232628

26242629
case CompressionMethod.Deflated:
26252630
var dos = new DeflaterOutputStream(result, new Deflater(9, true))
26262631
{
2627-
IsStreamOwner = false
2632+
// If there is an encryption stream in use, then we want that to be disposed when the deflator stream is disposed
2633+
// If not, then we don't want it to dispose the base stream
2634+
IsStreamOwner = entry.IsCrypted
26282635
};
26292636
result = dos;
26302637
break;

0 commit comments

Comments
 (0)