From 5ffd9e53bc26c4ca1500c99447c2a6daeee60aa7 Mon Sep 17 00:00:00 2001 From: homm Date: Thu, 26 May 2016 02:28:35 +0300 Subject: [PATCH] use calloc and INT_MAX --- Tests/test_image_resample.py | 1 - libImaging/Resample.c | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Tests/test_image_resample.py b/Tests/test_image_resample.py index 90dedae04..0b78217ce 100644 --- a/Tests/test_image_resample.py +++ b/Tests/test_image_resample.py @@ -151,7 +151,6 @@ class TestImagingCoreResampleAccuracy(PillowTestCase): 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]) diff --git a/libImaging/Resample.c b/libImaging/Resample.c index 6cb622f23..8ad1c9d97 100644 --- a/libImaging/Resample.c +++ b/libImaging/Resample.c @@ -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; @@ -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);