Skip to content

Commit

Permalink
fixes crash-74d2
Browse files Browse the repository at this point in the history
  • Loading branch information
wiredfool committed Mar 31, 2021
1 parent c54a7bb commit c290c1f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Binary file not shown.
2 changes: 2 additions & 0 deletions Tests/test_tiff_crashes.py
Expand Up @@ -33,6 +33,8 @@
"Tests/images/crash-86214e58da443d2b80820cff9677a38a33dcbbca.tif",
"Tests/images/crash-f46f5b2f43c370fe65706c11449f567ecc345e74.tif",
"Tests/images/crash-63b1dffefc8c075ddc606c0a2f5fdc15ece78863.tif",
"Tests/images/crash-74d2a78403a5a59db1fb0a2b8735ac068a75f6e3.tif",
],
)
@pytest.mark.filterwarnings("ignore:Possibly corrupt EXIF data")
Expand Down
30 changes: 17 additions & 13 deletions src/libImaging/TiffDecode.c
Expand Up @@ -265,7 +265,7 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) {
ret = TIFFGetFieldDefaulted(tiff, TIFFTAG_ROWSPERSTRIP, &rows_per_block);
}

if (ret != 1) {
if (ret != 1 || rows_per_block==(UINT32)(-1)) {
rows_per_block = state->ysize;
}

Expand All @@ -281,17 +281,6 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) {
img.req_orientation = ORIENTATION_TOPLEFT;
img.col_offset = 0;

if (state->xsize != img.width || state->ysize != img.height) {
TRACE(
("Inconsistent Image Error: %d =? %d, %d =? %d",
state->xsize,
img.width,
state->ysize,
img.height));
state->errcode = IMAGING_CODEC_BROKEN;
goto decodergba_err;
}

/* overflow check for row byte size */
if (INT_MAX / 4 < img.width) {
state->errcode = IMAGING_CODEC_MEMORY;
Expand Down Expand Up @@ -429,7 +418,7 @@ _decodeTile(Imaging im, ImagingCodecState state, TIFF *tiff, int planes, Imaging
for (x = state->xoff; x < state->xsize; x += tile_width) {
/* Sanity Check. Apparently in some cases, the TiffReadRGBA* functions
have a different view of the size of the tiff than we're getting from
other functions. So, we need to check here.
other functions. So, we need to check here.
*/
if (!TIFFCheckTile(tiff, x, y, 0, plane)) {
TRACE(("Check Tile Error, Tile at %dx%d\n", x, y));
Expand Down Expand Up @@ -568,6 +557,7 @@ ImagingLibTiffDecode(
uint16 planarconfig = 0;
int planes = 1;
ImagingShuffler unpackers[4];
UINT32 img_width, img_height;

memset(unpackers, 0, sizeof(ImagingShuffler) * 4);

Expand Down Expand Up @@ -664,6 +654,20 @@ ImagingLibTiffDecode(
}
}

TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &img_width);
TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &img_height);

if (state->xsize != img_width || state->ysize != img_height) {
TRACE(
("Inconsistent Image Error: %d =? %d, %d =? %d",
state->xsize,
img_width,
state->ysize,
img_height));
state->errcode = IMAGING_CODEC_BROKEN;
goto decode_err;
}


TIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &photometric);
TIFFGetField(tiff, TIFFTAG_COMPRESSION, &compression);
Expand Down

0 comments on commit c290c1f

Please sign in to comment.