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
20 changes: 20 additions & 0 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,26 @@ def test_non_bytes(
with pytest.raises(ValueError, match="Incorrect tag value type"):
im.save(out, tiffinfo=ifd)

@pytest.mark.parametrize(
"tiffinfo",
(
{TiffImagePlugin.IMAGEWIDTH: 1 << 27},
{TiffImagePlugin.SAMPLESPERPIXEL: 3},
),
)
def test_geometry_tags(
self, tiffinfo: dict[int, int], monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
# libtiff reads a scanline of the size described by the IMAGEWIDTH,
# SAMPLESPERPIXEL and BITSPERSAMPLE tags from a buffer that only holds one
# row of the image, so a tag describing a larger row must be rejected.
monkeypatch.setattr(TiffImagePlugin, "WRITE_LIBTIFF", True)

out = tmp_path / "temp.tif"
im = hopper("L")
with pytest.raises(OSError, match="encoder error -8"):
im.save(out, tiffinfo=tiffinfo)

def test_inknames_tag(
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
Expand Down
8 changes: 8 additions & 0 deletions src/libImaging/TiffDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,14 @@ ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int byt
TIFF *tiff = clientstate->tiff;

if (state->state == 0) {
// state->buffer holds one row of the image, but TIFFWriteScanline reads
// a scanline of the size described by the IMAGEWIDTH, SAMPLESPERPIXEL
// and BITSPERSAMPLE tags, so these must not describe a larger row.
if (TIFFScanlineSize64(tiff) > (uint64_t)state->bytes) {
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
}

// Encoding line by line
while (state->y < state->ysize) {
state->shuffle(
Expand Down
Loading