diff --git a/src/gd_gif_in.c b/src/gd_gif_in.c index 1ae0e32..2b6b34e 100644 --- a/src/gd_gif_in.c +++ b/src/gd_gif_in.c @@ -315,8 +315,10 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromGifCtx(gdIOCtxPtr fd) ReadImage(im, fd, width, height, localColorMap, BitSet(buf[8], INTERLACE), &ZeroDataBlock); } else { if(!haveGlobalColormap) { - gdImageDestroy(im); - return 0; + // Still a valid gif, apply simple default palette as per spec + ColorMap[CM_RED][1] = 0xff; + ColorMap[CM_GREEN][1] = 0xff; + ColorMap[CM_BLUE][1] = 0xff; } ReadImage(im, fd, width, height, ColorMap, BitSet(buf[8], INTERLACE), &ZeroDataBlock); diff --git a/tests/gdimagecrop/CMakeLists.txt b/tests/gdimagecrop/CMakeLists.txt index 43f6f6c..f5c309e 100644 --- a/tests/gdimagecrop/CMakeLists.txt +++ b/tests/gdimagecrop/CMakeLists.txt @@ -7,4 +7,10 @@ LIST(APPEND TESTS_FILES bug00486 ) +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + bug00486 +) +ENDIF(PNG_FOUND) + ADD_GD_TESTS() diff --git a/tests/gif/.gitignore b/tests/gif/.gitignore index 1b07664..d30118f 100644 --- a/tests/gif/.gitignore +++ b/tests/gif/.gitignore @@ -8,6 +8,7 @@ /bug00499 /gif_im2im /gif_null +/gif_nocolormaps /ossfuzz5700 /php_bug_75571 /uninitialized_memory_read diff --git a/tests/gif/CMakeLists.txt b/tests/gif/CMakeLists.txt index c4b9007..d071874 100644 --- a/tests/gif/CMakeLists.txt +++ b/tests/gif/CMakeLists.txt @@ -4,6 +4,7 @@ LIST(APPEND TESTS_FILES bug00227 bug00499 gif_null + gif_nocolormaps ossfuzz5700 php_bug_75571 uninitialized_memory_read diff --git a/tests/gif/Makemodule.am b/tests/gif/Makemodule.am index 9306b71..c616b3e 100644 --- a/tests/gif/Makemodule.am +++ b/tests/gif/Makemodule.am @@ -4,6 +4,7 @@ libgd_test_programs += \ gif/bug00227 \ gif/bug00499 \ gif/gif_null \ + gif/gif_nocolormaps \ gif/ossfuzz5700 \ gif/php_bug_75571 \ gif/uninitialized_memory_read \ @@ -27,6 +28,7 @@ EXTRA_DIST += \ gif/bug00060.gif \ gif/bug00066.gif \ gif/bug00066_exp.png \ + gif/gif_nocolormaps.gif \ gif/ossfuzz5700.gif \ gif/php_bug_75571.gif \ gif/unitialized_memory_read.gif diff --git a/tests/gif/gif_nocolormaps.c b/tests/gif/gif_nocolormaps.c new file mode 100644 index 0000000..4419904 --- /dev/null +++ b/tests/gif/gif_nocolormaps.c @@ -0,0 +1,25 @@ +/** + * Ensure that a GIF without any Global or Local color tables is still decoded + * + * GIF89a spec indicates conforming image files need not have Global or Local color tables at all + * + * See also: https://www.w3.org/Graphics/GIF/spec-gif89a.txt + * http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gif", "gif_nocolormaps.gif"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGif(fp); + gdTestAssert(im != NULL); + fclose(fp); + + return gdNumFailures(); +} diff --git a/tests/gif/gif_nocolormaps.gif b/tests/gif/gif_nocolormaps.gif new file mode 100644 index 0000000..b3aa80d Binary files /dev/null and b/tests/gif/gif_nocolormaps.gif differ