Skip to content

Commit 9569185

Browse files
committed
Fix PIZ decoding when image tile(bitmap) is composed of all black pixels. Fixes #194
1 parent 2a4dd61 commit 9569185

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tinyexr.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,7 +3200,13 @@ static bool DecompressPiz(unsigned char *outPtr, const unsigned char *inPtr,
32003200
ptr += maxNonZero - minNonZero + 1;
32013201
readLen += maxNonZero - minNonZero + 1;
32023202
} else {
3203-
return false;
3203+
// Issue 194
3204+
if ((minNonZero == (BITMAP_SIZE - 1)) && (maxNonZero == 0)) {
3205+
// OK. all pixels are zero. And no need to read `bitmap` data.
3206+
} else {
3207+
// invalid minNonZero/maxNonZero combination.
3208+
return false;
3209+
}
32043210
}
32053211

32063212
std::vector<unsigned short> lut(USHORT_RANGE);
@@ -3211,12 +3217,12 @@ static bool DecompressPiz(unsigned char *outPtr, const unsigned char *inPtr,
32113217
// Huffman decoding
32123218
//
32133219

3214-
int length;
3215-
32163220
if ((readLen + 4) > inLen) {
32173221
return false;
32183222
}
32193223

3224+
int length=0;
3225+
32203226
// length = *(reinterpret_cast<const int *>(ptr));
32213227
tinyexr::cpy4(&length, reinterpret_cast<const int *>(ptr));
32223228
ptr += sizeof(int);

0 commit comments

Comments
 (0)