Skip to content

Commit fb84701

Browse files
authored
Merge pull request #4034 from cgohlke/patch-1
Initialize rows_per_strip when RowsPerStrip tag is missing
2 parents b9693a5 + f5aed1a commit fb84701

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Tests/images/no_rows_per_strip.tif

3.96 MB
Binary file not shown.

Tests/test_file_libtiff.py

+7
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,13 @@ def test_old_style_jpeg(self):
832832
im, "Tests/images/old-style-jpeg-compression.png"
833833
)
834834

835+
def test_no_rows_per_strip(self):
836+
# This image does not have a RowsPerStrip TIFF tag
837+
infile = "Tests/images/no_rows_per_strip.tif"
838+
im = Image.open(infile)
839+
im.load()
840+
self.assertEqual(im.size, (950, 975))
841+
835842
def test_orientation(self):
836843
base_im = Image.open("Tests/images/g4_orientation_1.tif")
837844

src/libImaging/TiffDecode.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,12 @@ int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, Py_
405405
UINT32 strip_row, row_byte_size;
406406
UINT8 *new_data;
407407
UINT32 rows_per_strip;
408+
int ret;
408409

409-
TIFFGetField(tiff, TIFFTAG_ROWSPERSTRIP, &rows_per_strip);
410+
ret = TIFFGetField(tiff, TIFFTAG_ROWSPERSTRIP, &rows_per_strip);
411+
if (ret != 1) {
412+
rows_per_strip = state->ysize;
413+
}
410414
TRACE(("RowsPerStrip: %u \n", rows_per_strip));
411415

412416
// We could use TIFFStripSize, but for YCbCr data it returns subsampled data size

0 commit comments

Comments
 (0)