Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,22 @@ def test_realloc_overflow(self, monkeypatch: pytest.MonkeyPatch) -> None:
with pytest.raises(OSError, match="decoder error -9"):
im.load()

def test_rgba_rows_per_strip_greater_than_height(self) -> None:
# 1000x1 Deflate YCbCr strip with RowsPerStrip of 1,000,000
data = (
b"SUkqAAgAAAALAAABBAABAAAA6AMAAAEBBAABAAAAAQAAAAIBAwADAAAAkgAA"
b"AAMBAwABAAAACAAAAAYBAwABAAAABgAAABEBBAABAAAAmAAAABUBAwABAAAA"
b"AwAAABYBBAABAAAAQEIPABcBBAABAAAAGgAAABwBAwABAAAAAQAAABICAwAC"
b"AAAAAQABAAAAAAAIAAgACAB42u3BMQEAAADCoOqLbg0PoAAAgHcDDP7cTA=="
)
with Image.open(io.BytesIO(base64.b64decode(data))) as im:
assert isinstance(im, TiffImagePlugin.TiffImageFile)
assert im.tag_v2[TiffImagePlugin.ROWSPERSTRIP] == 1_000_000

# The decoding buffer is limited to the image height
im.load()
assert im.getpixel((0, 0)) == (128, 128, 128)

def test_unpacker_row_wider_than_libtiff_row(self) -> None:
for data in (
# 16x16 8-bit greyscale tile, with a PhotometricInterpretation tag that
Expand Down
3 changes: 2 additions & 1 deletion src/libImaging/TiffDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) {
ret = TIFFGetFieldDefaulted(tiff, TIFFTAG_ROWSPERSTRIP, &rows_per_block);
}

if (ret != 1 || rows_per_block == (UINT32)(-1)) {
if (ret != 1 || rows_per_block > (UINT32)state->ysize) {
// No more than the image height is needed for the buffer
rows_per_block = state->ysize;
}

Expand Down
Loading