mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
use calloc and INT_MAX
This commit is contained in:
parent
1c3def1d5a
commit
5ffd9e53bc
|
@ -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])
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user