--- xli-1.17.0.orig/new.c +++ xli-1.17.0/new.c @@ -104,6 +104,18 @@ lfree((byte *) rgb->blue); } +static unsigned int ovmul(unsigned int a, unsigned int b) +{ + unsigned int r; + + r = a * b; + if (r / a != b) { + memoryExhausted(); + } + + return r; +} + static Image *newImage(unsigned width, unsigned height) { Image *image; @@ -133,7 +145,7 @@ image->rgb.used = 2; image->depth = 1; linelen = ((width + 7) / 8); - image->data = (unsigned char *) lcalloc(linelen * height); + image->data = (unsigned char *) lcalloc(ovmul(linelen, height)); return image; } @@ -157,7 +169,8 @@ newRGBMapData(&(image->rgb), numcolors); image->depth = depth; image->pixlen = pixlen; - image->data = (unsigned char *) lmalloc(width * height * pixlen); + image->data = + (unsigned char *) lmalloc(ovmul(ovmul(width, height), pixlen)); return image; } @@ -172,7 +185,8 @@ image->rgb.used = image->rgb.size = 0; image->depth = 24; image->pixlen = 3; - image->data = (unsigned char *) lmalloc(width * height * 3); + image->data = + (unsigned char *) lmalloc(ovmul(ovmul(width, height), 3)); return image; }