Skip to content

Commit 8cc224a

Browse files
committed
Unit test for ZipInputStream.CanDecompressEntry being false for AES encrypted entries.
1 parent 119be15 commit 8cc224a

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
@@ -206,6 +206,40 @@ public void ZipFileStoreAesPartialRead()
206206
}
207207
}
208208

209+
/// <summary>
210+
/// ZipInputStream can't decrypt AES encrypted entries, but it should repot that to the caller
211+
/// rather than just failing.
212+
/// </summary>
213+
[Test]
214+
[Category("Zip")]
215+
public void ZipinputStreamShouldGracefullyFailWithAESStreams()
216+
{
217+
string password = "password";
218+
219+
using (var memoryStream = new MemoryStream())
220+
{
221+
// Try to create a zip stream
222+
WriteEncryptedZipToStream(memoryStream, password, 256);
223+
224+
// reset
225+
memoryStream.Seek(0, SeekOrigin.Begin);
226+
227+
// Try to read
228+
using (var inputStream = new ZipInputStream(memoryStream))
229+
{
230+
inputStream.Password = password;
231+
var entry = inputStream.GetNextEntry();
232+
Assert.That(entry.AESKeySize, Is.EqualTo(256), "Test entry should be AES256 encrypted.");
233+
234+
// CanDecompressEntry should be false.
235+
Assert.That(inputStream.CanDecompressEntry, Is.False, "CanDecompressEntry should be false for AES encrypted entries");
236+
237+
// Should throw on read.
238+
Assert.Throws<ZipException>(() => inputStream.ReadByte());
239+
}
240+
}
241+
}
242+
209243
private static readonly string[] possible7zPaths = new[] {
210244
// Check in PATH
211245
"7z", "7za",

0 commit comments

Comments
 (0)