- int width = *_width = cinfo.output_width;
- int height = *_height = cinfo.output_height;
- *dest = (unsigned char*)malloc(width*height*4);
+ unsigned int width = *_width = cinfo.output_width;
+ unsigned int height = *_height = cinfo.output_height;
+ unsigned long long int image_size = (unsigned long long)width * height * 4;
+ if(image_size > 0xffffffff) {
+ *_width = 0;
+ *_height = 0;
+ return 0;
+ }
+ *dest = (unsigned char*)malloc(image_size);