Merge pull request #939 from Morilli/fix-winaescryptostream-dispose

Fix WinzipAesCryptoStream potentially not getting disposed
This commit is contained in:
Adam Hathcock
2025-08-22 14:03:06 +01:00
committed by GitHub
3 changed files with 20 additions and 8 deletions

View File

@@ -70,17 +70,12 @@ internal abstract class ZipFilePart : FilePart
{
case ZipCompressionMethod.None:
{
if (stream is ReadOnlySubStream)
if (Header.CompressedSize is 0)
{
return stream;
return new DataDescriptorStream(stream);
}
if (Header.CompressedSize > 0)
{
return new ReadOnlySubStream(stream, Header.CompressedSize);
}
return new DataDescriptorStream(stream);
return stream;
}
case ZipCompressionMethod.Shrink:
{

View File

@@ -379,4 +379,21 @@ public class ZipReaderTests : ReaderTests
Assert.Equal(4, x);
}
[Fact]
public void Zip_Uncompressed_Encrypted_Read()
{
using var archive = ArchiveFactory.Open(
Path.Combine(TEST_ARCHIVES_PATH, "Zip.none.encrypted.zip"),
new ReaderOptions { Password = "test" }
);
using var reader = archive.ExtractAllEntries();
reader.MoveToNextEntry();
Assert.Equal("first.txt", reader.Entry.Key);
Assert.Equal(199, reader.Entry.Size);
reader.OpenEntryStream().Dispose();
reader.MoveToNextEntry();
Assert.Equal("second.txt", reader.Entry.Key);
Assert.Equal(197, reader.Entry.Size);
}
}

Binary file not shown.