From 499f5480f1a9b3063097b53592c37329c1d5f6f8 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 27 Aug 2017 13:53:39 +0200 Subject: Fixed bug #75124 (gdImageGrayScale() may produce colors) We have to make sure to avoid alpha-blending issues by explicitly switching to `gdEffectReplace` and to restore the old value afterwards. This is a port of . --- NEWS | 3 +++ ext/gd/libgd/gd_filter.c | 7 +++++++ ext/gd/tests/bug75124.phpt | 31 +++++++++++++++++++++++++++++++ ext/gd/tests/bug75124.png | Bin 0 -> 2436 bytes 4 files changed, 41 insertions(+) create mode 100644 ext/gd/tests/bug75124.phpt create mode 100644 ext/gd/tests/bug75124.png diff --git a/NEWS b/NEWS index edd4e29e54..bd93282df5 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,9 @@ PHP NEWS - CURL: . Fixed bug #75093 (OpenSSL support not detected). (Remi) +- GD: + . Fixed bug #75124 (gdImageGrayScale() may produce colors). (cmb) + - Intl: . Fixed bug #75090 (IntlGregorianCalendar doesn't have constants from parent class). (tpunt) diff --git a/ext/gd/libgd/gd_filter.c b/ext/gd/libgd/gd_filter.c index 22a393c126..fc48cd08de 100644 --- a/ext/gd/libgd/gd_filter.c +++ b/ext/gd/libgd/gd_filter.c @@ -53,12 +53,17 @@ int gdImageGrayScale(gdImagePtr src) int new_pxl, pxl; typedef int (*FuncPtr)(gdImagePtr, int, int); FuncPtr f; + int alpha_blending; + f = GET_PIXEL_FUNCTION(src); if (src==NULL) { return 0; } + alpha_blending = src->alphaBlendingFlag; + gdImageAlphaBlending(src, gdEffectReplace); + for (y=0; ysy; ++y) { for (x=0; xsx; ++x) { pxl = f (src, x, y); @@ -75,6 +80,8 @@ int gdImageGrayScale(gdImagePtr src) gdImageSetPixel (src, x, y, new_pxl); } } + gdImageAlphaBlending(src, alpha_blending); + return 1; } diff --git a/ext/gd/tests/bug75124.phpt b/ext/gd/tests/bug75124.phpt new file mode 100644 index 0000000000..b37afc9785 --- /dev/null +++ b/ext/gd/tests/bug75124.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #75124 (gdImageGrayScale() may produce colors) +--SKIPIF-- += 2.2.5'); +} +?> +--FILE-- +> 16) & 0xff; + $green = ($color >> 8) & 0xff; + $blue = $color & 0xff; + if ($red != $green || $green != $blue) { + echo "non grayscale pixel detected\n"; + break 2; + } + } +} +?> +===DONE=== +--EXPECT-- +bool(true) +===DONE=== diff --git a/ext/gd/tests/bug75124.png b/ext/gd/tests/bug75124.png new file mode 100644 index 0000000000..b5d5d1f4b2 Binary files /dev/null and b/ext/gd/tests/bug75124.png differ -- cgit v1.2.1