diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs index 688142f95..02fd30778 100644 --- a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs +++ b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs @@ -1289,7 +1289,7 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests) // If so until details are known we will be strict. if (entry.IsCrypted) { - if (compressedSize > ZipConstants.CryptoHeaderSize + 2) + if (compressedSize > entry.EncryptionOverheadSize + 2) { throw new ZipException("Directory compressed size invalid"); } @@ -1297,7 +1297,7 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests) else if (compressedSize > 2) { // When not compressed the directory size can validly be 2 bytes - // if the true size wasnt known when data was originally being written. + // if the true size wasn't known when data was originally being written. // NOTE: Versions of the library 0.85.4 and earlier always added 2 bytes throw new ZipException("Directory compressed size invalid"); } diff --git a/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs b/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs index 996b09213..7ae234523 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs @@ -875,13 +875,13 @@ public void TestDirectoryEntry() TestDirectoryEntry(new MemoryStreamWithoutSeek()); } - private void TestEncryptedDirectoryEntry(MemoryStream s) + private void TestEncryptedDirectoryEntry(MemoryStream s, int aesKeySize) { var outStream = new ZipOutputStream(s); outStream.Password = "Tonto hand me a beer"; outStream.IsStreamOwner = false; - outStream.PutNextEntry(new ZipEntry("YeUnreadableDirectory/")); + outStream.PutNextEntry(new ZipEntry("YeUnreadableDirectory/") { AESKeySize = aesKeySize } ); outStream.Close(); var ms2 = new MemoryStream(s.ToArray()); @@ -893,10 +893,10 @@ private void TestEncryptedDirectoryEntry(MemoryStream s) [Test] [Category("Zip")] - public void TestEncryptedDirectoryEntry() + public void TestEncryptedDirectoryEntry([Values(0, 128, 256)]int aesKeySize) { - TestEncryptedDirectoryEntry(new MemoryStream()); - TestEncryptedDirectoryEntry(new MemoryStreamWithoutSeek()); + TestEncryptedDirectoryEntry(new MemoryStream(), aesKeySize); + TestEncryptedDirectoryEntry(new MemoryStreamWithoutSeek(), aesKeySize); } [Test]