From a6008cde682aec612e46540bc47805bb91cf5f1a Mon Sep 17 00:00:00 2001 From: HowToDoThis Date: Thu, 12 Aug 2021 01:48:07 +0800 Subject: [PATCH] PR #577 Make ZipAESStream throw ZipException instead of Exception when the AES auth code is wrong --- src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs b/src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs index edba29f66..4410a0811 100644 --- a/src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs +++ b/src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs @@ -1,4 +1,6 @@ using ICSharpCode.SharpZipLib.Core; +using ICSharpCode.SharpZipLib.Zip; + using System; using System.IO; using System.Security.Cryptography; @@ -137,14 +139,14 @@ private int ReadAndTransform(byte[] buffer, int offset, int count) nBytes += TransformAndBufferBlock(buffer, offset, bytesLeftToRead, finalBlock); } else if (byteCount < AUTH_CODE_LENGTH) - throw new Exception("Internal error missed auth code"); // Coding bug + throw new ZipException("Internal error missed auth code"); // Coding bug // Final block done. Check Auth code. byte[] calcAuthCode = _transform.GetAuthCode(); for (int i = 0; i < AUTH_CODE_LENGTH; i++) { if (calcAuthCode[i] != _slideBuffer[_slideBufStartPos + i]) { - throw new Exception("AES Authentication Code does not match. This is a super-CRC check on the data in the file after compression and encryption. \r\n" + throw new ZipException("AES Authentication Code does not match. This is a super-CRC check on the data in the file after compression and encryption. \r\n" + "The file may be damaged."); } }