diff --git a/Tests/images/no_rows_per_strip.tif b/Tests/images/no_rows_per_strip.tif new file mode 100644 index 00000000000..67942aec40c Binary files /dev/null and b/Tests/images/no_rows_per_strip.tif differ diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 5bc20f62a10..ea73a7ad50a 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -832,6 +832,13 @@ def test_old_style_jpeg(self): im, "Tests/images/old-style-jpeg-compression.png" ) + def test_no_rows_per_strip(self): + # This image does not have a RowsPerStrip TIFF tag + infile = "Tests/images/no_rows_per_strip.tif" + im = Image.open(infile) + im.load() + self.assertEqual(im.size, (950, 975)) + def test_orientation(self): base_im = Image.open("Tests/images/g4_orientation_1.tif") diff --git a/src/libImaging/TiffDecode.c b/src/libImaging/TiffDecode.c index e72dae0c8e6..7592f7f39d1 100644 --- a/src/libImaging/TiffDecode.c +++ b/src/libImaging/TiffDecode.c @@ -405,8 +405,12 @@ int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, Py_ UINT32 strip_row, row_byte_size; UINT8 *new_data; UINT32 rows_per_strip; + int ret; - TIFFGetField(tiff, TIFFTAG_ROWSPERSTRIP, &rows_per_strip); + ret = TIFFGetField(tiff, TIFFTAG_ROWSPERSTRIP, &rows_per_strip); + if (ret != 1) { + rows_per_strip = state->ysize; + } TRACE(("RowsPerStrip: %u \n", rows_per_strip)); // We could use TIFFStripSize, but for YCbCr data it returns subsampled data size