Skip to content

Commit

Permalink
PR icsharpcode#577 Make ZipAESStream throw ZipException instead of Ex…
Browse files Browse the repository at this point in the history
…ception when the AES auth code is wrong
  • Loading branch information
HowToDoThis committed Aug 11, 2021
1 parent 6da2d18 commit a6008cd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions 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;
Expand Down Expand Up @@ -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.");
}
}
Expand Down

0 comments on commit a6008cd

Please sign in to comment.