Skip to content

Commit c7d21c5

Browse files
committed
Unit test for ZipInputStream.CanDecompressEntry being false for AES encrypted entries.
1 parent 9137c6b commit c7d21c5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/ICSharpCode.SharpZipLib.Tests/Zip/ZipEncryptionHandling.cs

+34
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,40 @@ public void ZipFileAESReadWithEmptyPassword()
399399
}
400400
}
401401

402+
/// <summary>
403+
/// ZipInputStream can't decrypt AES encrypted entries, but it should repot that to the caller
404+
/// rather than just failing.
405+
/// </summary>
406+
[Test]
407+
[Category("Zip")]
408+
public void ZipinputStreamShouldGracefullyFailWithAESStreams()
409+
{
410+
string password = "password";
411+
412+
using (var memoryStream = new MemoryStream())
413+
{
414+
// Try to create a zip stream
415+
WriteEncryptedZipToStream(memoryStream, password, 256);
416+
417+
// reset
418+
memoryStream.Seek(0, SeekOrigin.Begin);
419+
420+
// Try to read
421+
using (var inputStream = new ZipInputStream(memoryStream))
422+
{
423+
inputStream.Password = password;
424+
var entry = inputStream.GetNextEntry();
425+
Assert.That(entry.AESKeySize, Is.EqualTo(256), "Test entry should be AES256 encrypted.");
426+
427+
// CanDecompressEntry should be false.
428+
Assert.That(inputStream.CanDecompressEntry, Is.False, "CanDecompressEntry should be false for AES encrypted entries");
429+
430+
// Should throw on read.
431+
Assert.Throws<ZipException>(() => inputStream.ReadByte());
432+
}
433+
}
434+
}
435+
402436
private static readonly string[] possible7zPaths = new[] {
403437
// Check in PATH
404438
"7z", "7za",

0 commit comments

Comments
 (0)