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