diff --git a/Tests/test_imagewin.py b/Tests/test_imagewin.py index 36df32aff66..df50478a2c4 100644 --- a/Tests/test_imagewin.py +++ b/Tests/test_imagewin.py @@ -89,7 +89,7 @@ def test_dib_paste(self) -> None: def test_dib_paste_bbox(self) -> None: # Arrange im = hopper() - bbox = (0, 0, 10, 10) + bbox = (0, 0, 128, 128) mode = "RGBA" size = (128, 128) @@ -101,6 +101,9 @@ def test_dib_paste_bbox(self) -> None: # Assert assert dib.size == (128, 128) + with pytest.raises(ValueError, match="images do not match"): + dib.paste(im, (0, 0, 1, 1)) + def test_dib_frombytes_tobytes_roundtrip(self) -> None: # Arrange # Make two different DIB images diff --git a/src/display.c b/src/display.c index 944c60b704a..4a2d9d9b256 100644 --- a/src/display.c +++ b/src/display.c @@ -134,9 +134,13 @@ _paste(ImagingDisplayObject *display, PyObject *args) { if (xy[2] <= xy[0]) { xy[2] = xy[0] + im->xsize; + } else if (xy[2] - xy[0] != im->xsize) { + return ImagingError_Mismatch(); } if (xy[3] <= xy[1]) { xy[3] = xy[1] + im->ysize; + } else if (xy[3] - xy[1] != im->ysize) { + return ImagingError_Mismatch(); } ImagingPasteDIB(display->dib, im, xy);