check args before allocate memory

This commit is contained in:
Alexander 2017-08-05 18:59:16 +03:00
parent 430c53707f
commit 152104bba3

View File

@ -50,15 +50,16 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size)
{
Imaging im;
im = (Imaging) calloc(1, size);
if (!im)
return (Imaging) ImagingError_MemoryError();
/* linesize overflow check, roughly the current largest space req'd */
if (xsize > (INT_MAX / 4) - 1) {
return (Imaging) ImagingError_MemoryError();
}
im = (Imaging) calloc(1, size);
if (!im) {
return (Imaging) ImagingError_MemoryError();
}
/* Setup image descriptor */
im->xsize = xsize;
im->ysize = ysize;
@ -228,8 +229,7 @@ Imaging
ImagingNewPrologue(const char *mode, int xsize, int ysize)
{
return ImagingNewPrologueSubtype(
mode, xsize, ysize, sizeof(struct ImagingMemoryInstance)
);
mode, xsize, ysize, sizeof(struct ImagingMemoryInstance));
}
Imaging
@ -371,7 +371,6 @@ ImagingNewBlock(const char *mode, int xsize, int ysize)
}
im->destroy = ImagingDestroyBlock;
}
return ImagingNewEpilogue(im);