Skip to content

Commit

Permalink
Merge pull request #4034 from cgohlke/patch-1
Browse files Browse the repository at this point in the history
Initialize rows_per_strip when RowsPerStrip tag is missing
  • Loading branch information
radarhere authored Sep 30, 2019
2 parents b9693a5 + f5aed1a commit fb84701
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Binary file added Tests/images/no_rows_per_strip.tif
Binary file not shown.
7 changes: 7 additions & 0 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
6 changes: 5 additions & 1 deletion src/libImaging/TiffDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb84701

Please sign in to comment.