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
14 changes: 14 additions & 0 deletions Tests/test_image_paste.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,20 @@ def test_different_sizes(self) -> None:
im.copy().paste(im2)
im.copy().paste(im2, (0, 0))

@pytest.mark.parametrize(
"box",
(
(2**31 - 1, 0, -(2**31), 1),
(0, 2**31 - 1, 1, -(2**31)),
),
)
def test_overflow(self, box: tuple[int, int, int, int]) -> None:
im = Image.new("1", (1, 1))
im.paste(1, box)

with pytest.raises(ValueError, match="images do not match"):
im.paste(im.copy(), box)

def test_incorrect_abbreviated_form(self) -> None:
im = Image.new("L", (1, 1))
with pytest.raises(ValueError):
Expand Down
12 changes: 6 additions & 6 deletions src/libImaging/Paste.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ int
ImagingPaste(
Imaging imOut, Imaging imIn, Imaging imMask, int dx0, int dy0, int dx1, int dy1
) {
int xsize, ysize;
int64_t xsize, ysize;
int pixelsize;
int sx0, sy0;
ImagingSectionCookie cookie;
Expand All @@ -286,8 +286,8 @@ ImagingPaste(

pixelsize = imOut->pixelsize;

xsize = dx1 - dx0;
ysize = dy1 - dy0;
xsize = (int64_t)dx1 - dx0;
ysize = (int64_t)dy1 - dy0;

if (xsize != imIn->xsize || ysize != imIn->ysize || pixelsize != imIn->pixelsize) {
(void)ImagingError_Mismatch();
Expand Down Expand Up @@ -598,7 +598,7 @@ ImagingFill2(
Imaging imOut, const void *ink, Imaging imMask, int dx0, int dy0, int dx1, int dy1
) {
ImagingSectionCookie cookie;
int xsize, ysize;
int64_t xsize, ysize;
int pixelsize;
int sx0, sy0;

Expand All @@ -609,8 +609,8 @@ ImagingFill2(

pixelsize = imOut->pixelsize;

xsize = dx1 - dx0;
ysize = dy1 - dy0;
xsize = (int64_t)dx1 - dx0;
ysize = (int64_t)dy1 - dy0;

if (imMask && (xsize != imMask->xsize || ysize != imMask->ysize)) {
(void)ImagingError_Mismatch();
Expand Down
Loading