Skip to content

Commit

Permalink
[SharpZipLib] - Fixes: icsharpcode/SharpZipLib#837
Browse files Browse the repository at this point in the history
[SharpZipLib] - Fixes: icsharpcode/SharpZipLib#837
  • Loading branch information
GitHubProUser67 committed Oct 21, 2024
1 parent a27512c commit 90354fc
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,19 +396,28 @@ private bool DecodeHuffman()
/// </exception>
private bool DecodeChksum()
{
int numOfChksumBits = 8;

while (neededBits > 0)
{
int chkByte = input.PeekBits(8);
// Some Adobe files has an encoding error that screw up their Checksum : https://github.com/icsharpcode/SharpZipLib/issues/837
if (input.AvailableBits < 8)
numOfChksumBits = input.AvailableBits;
else
numOfChksumBits = 8;

int chkByte = input.PeekBits(numOfChksumBits);
if (chkByte < 0)
{
return false;
}
input.DropBits(8);
readAdler = (readAdler << 8) | chkByte;
input.DropBits(numOfChksumBits);
readAdler = (readAdler << numOfChksumBits) | chkByte;
neededBits -= 8;
}

if ((int)adler?.Value != readAdler)
// Skips Checkum check for invalid data
if (numOfChksumBits == 8 && (int)adler?.Value != readAdler)
{
throw new SharpZipBaseException("Adler chksum doesn't match: " + (int)adler?.Value + " vs. " + readAdler);
}
Expand Down

0 comments on commit 90354fc

Please sign in to comment.