gif2webp: fix segfault on OOM
previously calls to WebPPictureCopy() weren't checked, causing a crash
when the canvas copies were accessed later in the loop
Tested:
for i in `seq 1 1125`; do
export MALLOC_FAIL_AT=$i
./examples/gif2webp gif_file
./examples/gif2webp -mixed gif_file
done
@@ -314,8 +314,11 @@ int main(int argc, const char* argv[]) {
frame.use_argb = 1;
if (!WebPPictureAlloc(&frame)) goto End;
GIFClearPic(&frame, NULL);
- WebPPictureCopy(&frame, &curr_canvas);
- WebPPictureCopy(&frame, &prev_canvas);
+ if (!(WebPPictureCopy(&frame, &curr_canvas) &&
+ WebPPictureCopy(&frame, &prev_canvas))) {
+ fprintf(stderr, "Error allocating canvas.\n");
+ goto End;
+ }
// Background color.
GIFGetBackgroundColor(gif->SColorMap, gif->SBackGroundColor,
