Skip to content

Commit

Permalink
backported some GifLib patches affecting #38
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Szabo committed Aug 6, 2018
1 parent af05f34 commit 3eea9c4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cgif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,12 @@ static int DGifDecompressInput(GifFilePrivateType *Private, int *Code)
0x0fff
};

/* The image can't contain more than LZ_BITS per code. */
if (Private->RunningBits > LZ_BITS) {
return GIF_ERROR;
}


while (Private->CrntShiftState < Private->RunningBits) {
/* Needs to get more bytes from input stream for next code: */
if (DGifBufferedInput(Private->File, Private->Buf, &NextByte)
Expand All @@ -1383,9 +1389,12 @@ static int DGifDecompressInput(GifFilePrivateType *Private, int *Code)
Private->CrntShiftDWord >>= Private->RunningBits;
Private->CrntShiftState -= Private->RunningBits;

/* If code cannt fit into RunningBits bits, must raise its size. Note */
/* however that codes above 4095 are used for special signaling. */
if (++Private->RunningCode > Private->MaxCode1 &&
/* If code cannt fit into RunningBits bits, must raise its size. Note */
/* however that codes above 4095 are used for special signaling. */
/* If we're using LZ_BITS bits already and we're at the max code, just */
/* keep using the table as it is, don't increment Private->RunningCode.*/
if (Private->RunningCode < LZ_MAX_CODE + 2 &&
++Private->RunningCode > Private->MaxCode1 &&
Private->RunningBits < LZ_BITS) {
Private->MaxCode1 <<= 1;
Private->RunningBits++;
Expand Down

0 comments on commit 3eea9c4

Please sign in to comment.