Skip to content

Commit

Permalink
sanity check data reads from PIZ data
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>
  • Loading branch information
peterhillman committed Feb 4, 2020
1 parent 43cd3ad commit ea33498
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions OpenEXR/IlmImf/ImfPizCompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,9 @@ PizCompressor::uncompress (const char *inPtr,
// This is the cunompress function which is used by both the tiled and
// scanline decompression routines.
//


const char* inputEnd=inPtr+inSize;

//
// Special case - empty input buffer
//
Expand All @@ -503,6 +505,7 @@ PizCompressor::uncompress (const char *inPtr,
return 0;
}


//
// Determine the layout of the compressed pixel data
//
Expand Down Expand Up @@ -549,6 +552,12 @@ PizCompressor::uncompress (const char *inPtr,
AutoArray <unsigned char, BITMAP_SIZE> bitmap;
memset (bitmap, 0, sizeof (unsigned char) * BITMAP_SIZE);


if(inPtr + sizeof(unsigned short)*2 > inputEnd)
{
throw InputExc ("PIZ compressed data too short");
}

Xdr::read <CharPtrIO> (inPtr, minNonZero);
Xdr::read <CharPtrIO> (inPtr, maxNonZero);

Expand All @@ -560,8 +569,14 @@ PizCompressor::uncompress (const char *inPtr,

if (minNonZero <= maxNonZero)
{
Xdr::read <CharPtrIO> (inPtr, (char *) &bitmap[0] + minNonZero,
maxNonZero - minNonZero + 1);
size_t bytesToRead = maxNonZero - minNonZero + 1;
if(inPtr + bytesToRead > inputEnd)
{
throw InputExc ("PIZ compressed data too short");
}

Xdr::read <CharPtrIO> (inPtr, (char *) &bitmap[0] + minNonZero,
bytesToRead);
}

AutoArray <unsigned short, USHORT_RANGE> lut;
Expand All @@ -570,6 +585,11 @@ PizCompressor::uncompress (const char *inPtr,
//
// Huffman decoding
//
if(inPtr + sizeof(int)> inputEnd)
{
throw InputExc ("PIZ compressed data too short");
}


int length;
Xdr::read <CharPtrIO> (inPtr, length);
Expand Down

0 comments on commit ea33498

Please sign in to comment.