Skip to content

Commit b39bc8d

Browse files
committed
Unit test for ZipInputStream.CanDecompressEntry being false for AES encrypted entries.
1 parent 0f54e1d commit b39bc8d

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
@@ -365,6 +365,40 @@ public void ZipFileAesDelete()
365365
}
366366
}
367367

368+
/// <summary>
369+
/// ZipInputStream can't decrypt AES encrypted entries, but it should repot that to the caller
370+
/// rather than just failing.
371+
/// </summary>
372+
[Test]
373+
[Category("Zip")]
374+
public void ZipinputStreamShouldGracefullyFailWithAESStreams()
375+
{
376+
string password = "password";
377+
378+
using (var memoryStream = new MemoryStream())
379+
{
380+
// Try to create a zip stream
381+
WriteEncryptedZipToStream(memoryStream, password, 256);
382+
383+
// reset
384+
memoryStream.Seek(0, SeekOrigin.Begin);
385+
386+
// Try to read
387+
using (var inputStream = new ZipInputStream(memoryStream))
388+
{
389+
inputStream.Password = password;
390+
var entry = inputStream.GetNextEntry();
391+
Assert.That(entry.AESKeySize, Is.EqualTo(256), "Test entry should be AES256 encrypted.");
392+
393+
// CanDecompressEntry should be false.
394+
Assert.That(inputStream.CanDecompressEntry, Is.False, "CanDecompressEntry should be false for AES encrypted entries");
395+
396+
// Should throw on read.
397+
Assert.Throws<ZipException>(() => inputStream.ReadByte());
398+
}
399+
}
400+
}
401+
368402
private static readonly string[] possible7zPaths = new[] {
369403
// Check in PATH
370404
"7z", "7za",

0 commit comments

Comments
 (0)