Skip to content

Commit a6008cd

Browse files
committed
PR icsharpcode#577 Make ZipAESStream throw ZipException instead of Exception when the AES auth code is wrong
1 parent 6da2d18 commit a6008cd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using ICSharpCode.SharpZipLib.Core;
2+
using ICSharpCode.SharpZipLib.Zip;
3+
24
using System;
35
using System.IO;
46
using System.Security.Cryptography;
@@ -137,14 +139,14 @@ private int ReadAndTransform(byte[] buffer, int offset, int count)
137139
nBytes += TransformAndBufferBlock(buffer, offset, bytesLeftToRead, finalBlock);
138140
}
139141
else if (byteCount < AUTH_CODE_LENGTH)
140-
throw new Exception("Internal error missed auth code"); // Coding bug
142+
throw new ZipException("Internal error missed auth code"); // Coding bug
141143
// Final block done. Check Auth code.
142144
byte[] calcAuthCode = _transform.GetAuthCode();
143145
for (int i = 0; i < AUTH_CODE_LENGTH; i++)
144146
{
145147
if (calcAuthCode[i] != _slideBuffer[_slideBufStartPos + i])
146148
{
147-
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"
149+
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"
148150
+ "The file may be damaged.");
149151
}
150152
}

0 commit comments

Comments
 (0)