Skip to content

Commit

Permalink
Added bounds checking to prevent lzwImageData buffer overflow, part of
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Beaudoin committed Oct 3, 2014
1 parent a52e8a0 commit acf5d60
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion GIFParseFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,24 @@ void parseTableBasedImage() {
int dataBlockSize = readByte();
while (dataBlockSize != 0) {
#if DEBUG == 1
Serial.print("datablocksize: ");
Serial.print("dataBlockSize: ");
Serial.println(dataBlockSize);
#endif
backUpStream(1);
dataBlockSize++;
// quick fix to prevent a crash if lzwImageData is not large enough
if(offset + dataBlockSize <= sizeof(lzwImageData)) {
readIntoBuffer(lzwImageData + offset, dataBlockSize);
} else {
int i;
// discard the data block that would cause a buffer overflow
for(i=0; i<dataBlockSize; i++)
file.read();
#if DEBUG == 1
Serial.print("******* Prevented lzwImageData Overflow ******");
#endif
}

offset += dataBlockSize;
dataBlockSize = readByte();
}
Expand Down

0 comments on commit acf5d60

Please sign in to comment.