Skip to content

Commit

Permalink
PR #577: Throw ZipException in ZipAESStream instead of generic Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Numpsy committed Feb 21, 2021
1 parent c814877 commit 3617fb9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Security.Cryptography;
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;

namespace ICSharpCode.SharpZipLib.Encryption
{
Expand Down Expand Up @@ -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.");
}
}
Expand Down

0 comments on commit 3617fb9

Please sign in to comment.