Skip to content

Commit c78aa9a

Browse files
author
Remo Gloor
committed
Fixed incompatibility with coding style.
1 parent 1964c55 commit c78aa9a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/ICSharpCode.SharpZipLib/Zip/ZipInputStream.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ protected override void StopDecrypting()
351351

352352
if (authBytesRead < ZipConstants.AESAuthCodeLength)
353353
{
354-
throw new Exception("Internal error missed auth code"); // Coding bug
354+
throw new ZipException("Internal error missed auth code"); // Coding bug
355355
// Final block done. Check Auth code.
356356
}
357357

@@ -360,7 +360,7 @@ protected override void StopDecrypting()
360360
{
361361
if (calcAuthCode[i] != authBytes[i])
362362
{
363-
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"
363+
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"
364364
+ "The file may be damaged or tampered.");
365365
}
366366
}
@@ -592,21 +592,27 @@ private int InitialRead(byte[] destination, int offset, int count)
592592
int saltIn = inputBuffer.ReadRawBuffer(saltBytes, 0, saltLen);
593593

594594
if (saltIn != saltLen)
595+
{
595596
throw new ZipException("AES Salt expected " + saltLen + " got " + saltIn);
597+
}
596598

597599
//
598600
byte[] pwdVerifyRead = new byte[ZipConstants.AESPasswordVerifyLength];
599601
int pwdBytesRead = inputBuffer.ReadRawBuffer(pwdVerifyRead, 0, pwdVerifyRead.Length);
600602

601603
if (pwdBytesRead != pwdVerifyRead.Length)
604+
{
602605
throw new EndOfStreamException();
606+
}
603607

604608
int blockSize = entry.AESKeySize / 8; // bits to bytes
605609

606610
var decryptor = new ZipAESTransform(password, saltBytes, blockSize, false);
607611
byte[] pwdVerifyCalc = decryptor.PwdVerifier;
608612
if (pwdVerifyCalc[0] != pwdVerifyRead[0] || pwdVerifyCalc[1] != pwdVerifyRead[1])
613+
{
609614
throw new ZipException("Invalid password for AES");
615+
}
610616

611617
// The AES data has saltLen+AESPasswordVerifyLength bytes as a header, and AESAuthCodeLength bytes
612618
// as a footer.
@@ -756,6 +762,8 @@ private int BodyRead(byte[] buffer, int offset, int count)
756762
}
757763
}
758764
break;
765+
default:
766+
throw new InvalidOperationException("Internal Error: Unsupported compression method encountered.");
759767
}
760768

761769
if (count > 0)

test/ICSharpCode.SharpZipLib.Tests/Zip/ZipEncryptionHandling.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void ZipInputStreamDecryption(int aesKeySize, CompressionMethod compressi
148148

149149
for (int i = 0; i < 3; i++)
150150
{
151-
var hmm = zis.GetNextEntry();
151+
zis.GetNextEntry();
152152

153153
using (var sr = new StreamReader(zis, Encoding.UTF8, leaveOpen: true, detectEncodingFromByteOrderMarks: true, bufferSize: 1024))
154154
{

0 commit comments

Comments
 (0)