mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-11-16 17:31:10 +00:00
Merge pull request #939 from Morilli/fix-winaescryptostream-dispose
Fix WinzipAesCryptoStream potentially not getting disposed
This commit is contained in:
@@ -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:
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
tests/TestArchives/Archives/Zip.none.encrypted.zip
Normal file
BIN
tests/TestArchives/Archives/Zip.none.encrypted.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user