mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 09:44:31 +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;
|
kmax = (int) ceil(support) * 2 + 1;
|
||||||
|
|
||||||
// check for overflow
|
// check for overflow
|
||||||
if (kmax > 0 && xsize > SIZE_MAX / kmax)
|
if (xsize > SIZE_MAX / (kmax * sizeof(float)))
|
||||||
return (Imaging) ImagingError_MemoryError();
|
return (Imaging) ImagingError_MemoryError();
|
||||||
|
|
||||||
// sizeof(float) should be greater than 0
|
// sizeof(int) should be greater than 0 as well
|
||||||
if (xsize * kmax > SIZE_MAX / sizeof(float))
|
if (xsize > SIZE_MAX / (2 * sizeof(int)))
|
||||||
return (Imaging) ImagingError_MemoryError();
|
return (Imaging) ImagingError_MemoryError();
|
||||||
|
|
||||||
/* coefficient buffer */
|
/* coefficient buffer */
|
||||||
|
@ -151,10 +151,6 @@ ImagingResampleHorizontal(Imaging imIn, int xsize, int filter)
|
||||||
if ( ! kk)
|
if ( ! kk)
|
||||||
return (Imaging) ImagingError_MemoryError();
|
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));
|
xbounds = malloc(xsize * 2 * sizeof(int));
|
||||||
if ( ! xbounds) {
|
if ( ! xbounds) {
|
||||||
free(kk);
|
free(kk);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user