Avoid crashes when trying to load bad GIF files

* src/image.c (gif_load): Handle the case when GifErrorString
returns NULL.  (Bug#43281)
This commit is contained in:
Eli Zaretskii 2020-09-08 19:17:23 +03:00
parent 7938713105
commit 366a97c980

View file

@ -8160,11 +8160,13 @@ gif_load (struct frame *f, struct image *img)
if (gif == NULL) if (gif == NULL)
{ {
#if HAVE_GIFERRORSTRING #if HAVE_GIFERRORSTRING
image_error ("Cannot open `%s': %s", const char *errstr = GifErrorString (gif_err);
file, build_string (GifErrorString (gif_err))); if (errstr)
#else image_error ("Cannot open `%s': %s", file, build_string (errstr));
image_error ("Cannot open `%s'", file); else
#endif #endif
image_error ("Cannot open `%s'", file);
return 0; return 0;
} }
} }
@ -8190,11 +8192,13 @@ gif_load (struct frame *f, struct image *img)
if (!gif) if (!gif)
{ {
#if HAVE_GIFERRORSTRING #if HAVE_GIFERRORSTRING
const char *errstr = GifErrorString (gif_err);
if (errstr)
image_error ("Cannot open memory source `%s': %s", image_error ("Cannot open memory source `%s': %s",
img->spec, build_string (GifErrorString (gif_err))); img->spec, build_string (errstr));
#else else
image_error ("Cannot open memory source `%s'", img->spec);
#endif #endif
image_error ("Cannot open memory source `%s'", img->spec);
return 0; return 0;
} }
} }
@ -8474,9 +8478,9 @@ gif_load (struct frame *f, struct image *img)
if (error_text) if (error_text)
image_error ("Error closing `%s': %s", image_error ("Error closing `%s': %s",
img->spec, build_string (error_text)); img->spec, build_string (error_text));
#else else
image_error ("Error closing `%s'", img->spec);
#endif #endif
image_error ("Error closing `%s'", img->spec);
} }
/* Maybe fill in the background field while we have ximg handy. */ /* Maybe fill in the background field while we have ximg handy. */