From 0cbcd115e8849d7709f548a56050193a3a0d5d59 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Sun, 14 Feb 2021 21:33:03 +0000 Subject: [PATCH] Make ZipAESStream throw ZipException instead of Exception when the auto code is wrong --- src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs b/src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs index 4f649e8a9..4bf01300b 100644 --- a/src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs +++ b/src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs @@ -2,6 +2,7 @@ using System.IO; using System.Security.Cryptography; using ICSharpCode.SharpZipLib.Core; +using ICSharpCode.SharpZipLib.Zip; namespace ICSharpCode.SharpZipLib.Encryption { @@ -137,14 +138,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."); } }