From 38365a44d04ce60b97f13b63e9eebb07c77fe010 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 5 Jan 2025 11:23:15 +0100 Subject: [PATCH] Add support for reading GIFs without colormap Cf. . Closes GH-17364. --- NEWS | 2 ++ ext/gd/libgd/gd_gif_in.c | 6 ++++-- ext/gd/tests/gif_nocolormaps.gif | Bin 0 -> 37 bytes ext/gd/tests/gif_nocolormaps.phpt | 11 +++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 ext/gd/tests/gif_nocolormaps.gif create mode 100644 ext/gd/tests/gif_nocolormaps.phpt diff --git a/NEWS b/NEWS index 1664d0a8d8105..816055b981828 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ PHP NEWS images). (cmb) . Ported fix for libgd 223 (gdImageRotateGeneric() does not properly interpolate). (cmb) + . Added support for reading GIFs without colormap to bundled libgd. (Andrew + Burley, cmb) - Intl: . Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos) diff --git a/ext/gd/libgd/gd_gif_in.c b/ext/gd/libgd/gd_gif_in.c index 6fb79fd00b6ba..0204c4158db4a 100644 --- a/ext/gd/libgd/gd_gif_in.c +++ b/ext/gd/libgd/gd_gif_in.c @@ -244,8 +244,10 @@ gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr fd) /* {{{ */ 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, diff --git a/ext/gd/tests/gif_nocolormaps.gif b/ext/gd/tests/gif_nocolormaps.gif new file mode 100644 index 0000000000000000000000000000000000000000..b3aa80d843a929ce4e5af18912072ba4157c115b GIT binary patch literal 37 kcmZ?wbhEHbWMp7u00PCIER0-0rVfY$7Gq-aVPvod09bhgj{pDw literal 0 HcmV?d00001 diff --git a/ext/gd/tests/gif_nocolormaps.phpt b/ext/gd/tests/gif_nocolormaps.phpt new file mode 100644 index 0000000000000..c962c0e9b20fd --- /dev/null +++ b/ext/gd/tests/gif_nocolormaps.phpt @@ -0,0 +1,11 @@ +--TEST-- +A GIF without any Global or Local color tables is still decoded +--EXTENSIONS-- +gd +--FILE-- + +--EXPECT-- +bool(true)