mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
move checks before mallocs to prevent memory leaks
This commit is contained in:
parent
73c81404e6
commit
a5b99dd302
|
@ -139,11 +139,11 @@ ImagingResampleHorizontal(Imaging imIn, int xsize, int filter)
|
|||
kmax = (int) ceil(support) * 2 + 1;
|
||||
|
||||
// check for overflow
|
||||
if (kmax > 0 && xsize > SIZE_MAX / kmax)
|
||||
if (xsize > SIZE_MAX / (kmax * sizeof(float)))
|
||||
return (Imaging) ImagingError_MemoryError();
|
||||
|
||||
// sizeof(float) should be greater than 0
|
||||
if (xsize * kmax > SIZE_MAX / sizeof(float))
|
||||
// sizeof(int) should be greater than 0 as well
|
||||
if (xsize > SIZE_MAX / (2 * sizeof(int)))
|
||||
return (Imaging) ImagingError_MemoryError();
|
||||
|
||||
/* coefficient buffer */
|
||||
|
@ -151,10 +151,6 @@ ImagingResampleHorizontal(Imaging imIn, int xsize, int filter)
|
|||
if ( ! kk)
|
||||
return (Imaging) ImagingError_MemoryError();
|
||||
|
||||
// sizeof(int) should be greater than 0 as well
|
||||
if (xsize > SIZE_MAX / (2 * sizeof(int)))
|
||||
return (Imaging) ImagingError_MemoryError();
|
||||
|
||||
xbounds = malloc(xsize * 2 * sizeof(int));
|
||||
if ( ! xbounds) {
|
||||
free(kk);
|
||||
|
|
Loading…
Reference in New Issue
Block a user