FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use int64_t to calculate paste box dimensions by radarhere · Pull Request #9703 · python-pillow/Pillow · GitHub

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

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 14 additions & 0 deletions Tests/test_image_paste.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL