Skip to content
Open
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
15 changes: 15 additions & 0 deletions Tests/test_imagewin.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ def test_dib_paste_bbox(self) -> None:
with pytest.raises(ValueError, match="images do not match"):
dib.paste(im, (0, 0, 1, 1))

with pytest.raises(ValueError, match="left box co-ordinate cannot be negative"):
dib.paste(im, (-1, 0, 127, 128))
with pytest.raises(
ValueError, match="right box co-ordinate outside bitmap image"
):
dib.paste(im, (128, 0, 256, 128))
with pytest.raises(
ValueError, match="upper box co-ordinate cannot be negative"
):
dib.paste(im, (0, -1, 128, 127))
with pytest.raises(
ValueError, match="lower box co-ordinate outside bitmap image"
):
dib.paste(im, (0, 128, 128, 256))

def test_dib_frombytes_tobytes_roundtrip(self) -> None:
# Arrange
# Make two different DIB images
Expand Down
16 changes: 16 additions & 0 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,27 @@ _paste(ImagingDisplayObject *display, PyObject *args) {
} else if (xy[2] - xy[0] != im->xsize) {
return ImagingError_Mismatch();
}
if (xy[0] < 0) {
PyErr_SetString(PyExc_ValueError, "left box co-ordinate cannot be negative");
return NULL;
}
if (xy[2] > display->dib->xsize) {
PyErr_SetString(PyExc_ValueError, "right box co-ordinate outside bitmap image");
return NULL;
}
if (xy[3] <= xy[1]) {
xy[3] = xy[1] + im->ysize;
} else if (xy[3] - xy[1] != im->ysize) {
return ImagingError_Mismatch();
}
if (xy[1] < 0) {
PyErr_SetString(PyExc_ValueError, "upper box co-ordinate cannot be negative");
return NULL;
}
if (xy[3] > display->dib->ysize) {
PyErr_SetString(PyExc_ValueError, "lower box co-ordinate outside bitmap image");
return NULL;
}

ImagingPasteDIB(display->dib, im, xy);

Expand Down
3 changes: 0 additions & 3 deletions src/libImaging/Dib.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ ImagingNewDIB(const ModeID mode, int xsize, int ysize) {
void
ImagingPasteDIB(ImagingDIB dib, Imaging im, int xy[4]) {
/* Paste image data into a bitmap */

/* FIXME: check size! */

int y;
for (y = 0; y < im->ysize; y++) {
dib->pack(
Expand Down
Loading