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

Change-Id: I186d13be0ec8f3b72b7d247a8482590c1b1be541
This commit is contained in:
James Zern 2022-04-04 10:54:58 -07:00
parent 0957fd69ee
commit e471728754

View File

@ -314,8 +314,11 @@ int main(int argc, const char* argv[]) {
frame.use_argb = 1; frame.use_argb = 1;
if (!WebPPictureAlloc(&frame)) goto End; if (!WebPPictureAlloc(&frame)) goto End;
GIFClearPic(&frame, NULL); GIFClearPic(&frame, NULL);
WebPPictureCopy(&frame, &curr_canvas); if (!(WebPPictureCopy(&frame, &curr_canvas) &&
WebPPictureCopy(&frame, &prev_canvas); WebPPictureCopy(&frame, &prev_canvas))) {
fprintf(stderr, "Error allocating canvas.\n");
goto End;
}
// Background color. // Background color.
GIFGetBackgroundColor(gif->SColorMap, gif->SBackGroundColor, GIFGetBackgroundColor(gif->SColorMap, gif->SBackGroundColor,