Skip to content

Commit

Permalink
use calloc and INT_MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
homm committed May 25, 2016
1 parent 1c3def1 commit 5ffd9e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 0 additions & 1 deletion Tests/test_image_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def test_enlarge_lanczos(self):


class CoreResampleConsistencyTest(PillowTestCase):

def make_case(self, mode, fill):
im = Image.new(mode, (512, 9), fill)
return (im.resize((9, 512), Image.LANCZOS), im.load()[0, 0])
Expand Down
10 changes: 5 additions & 5 deletions libImaging/Resample.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ ImagingPrecompute(int inSize, int outSize, struct filter *filterp,
kmax = (int) ceil(support) * 2 + 1;

// check for overflow
if (outSize > SIZE_MAX / (kmax * sizeof(double)))
if (outSize > INT_MAX / (kmax * sizeof(double)))
return 0;

// sizeof(double) should be greater than 0 as well
if (outSize > SIZE_MAX / (2 * sizeof(double)))
if (outSize > INT_MAX / (2 * sizeof(double)))
return 0;

/* coefficient buffer */
kk = malloc(outSize * kmax * sizeof(double));
kk = calloc(outSize * kmax, sizeof(double));
if ( ! kk)
return 0;

xbounds = malloc(outSize * 2 * sizeof(int));
xbounds = calloc(outSize * 2, sizeof(int));
if ( ! xbounds) {
free(kk);
return 0;
Expand Down Expand Up @@ -160,7 +160,7 @@ ImagingResampleHorizontal_8bpc(Imaging imIn, int xsize, struct filter *filterp)
return (Imaging) ImagingError_MemoryError();
}

kk = malloc(xsize * kmax * sizeof(int));
kk = calloc(xsize * kmax, sizeof(int));
if ( ! kk) {
free(xbounds);
free(prekk);
Expand Down

0 comments on commit 5ffd9e5

Please sign in to comment.