com php-src: Fixed bug #75124 (gdImageGrayScale() may produce colors): NEWS ext/gd/libgd/gd_filter.c ext/gd/tests/bug75124 .phpt
ext/gd/tests/bug75124.png

From: Date: Sun, 27 Aug 2017 11:53:39 +0000
Subject: com php-src: Fixed bug #75124 (gdImageGrayScale() may produce colors): NEWS ext/gd/libgd/gd_filter.c ext/gd/tests/bug75124 .phpt
ext/gd/tests/bug75124.png
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-99173@lists.php.net to get a copy of this message
Commit: 499f5480f1a9b3063097b53592c37329c1d5f6f8 Author: Christoph M. Becker <cmbecker69@gmx.de> Sun, 27 Aug 2017 13:53:39 +0200 Parents: be9edd83c2b3119018611e178da0ee55f7b71c28 Branches: PHP-7.0 PHP-7..1 PHP-7.2 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=499f5480f1a9b3063097b53592c37329c1d5f6f8 Log: 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 <https://github.com/libgd/libgd/commit/a7a7ece>. Bugs: https://bugs.php.net/75124 Changed paths: M NEWS M ext/gd/libgd/gd_filter.c A ext/gd/tests/bug75124.phpt A ext/gd/tests/bug75124.png Diff: diff --git a/NEWS b/NEWS index edd4e29..bd93282 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 22a393c..fc48cd0 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; y<src->sy; ++y) { for (x=0; x<src->sx; ++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 0000000..b37afc9 --- /dev/null +++ b/ext/gd/tests/bug75124.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #75124 (gdImageGrayScale() may produce colors) +--SKIPIF-- +<?php +if (!extension_loaded('gd')) die('gd extension not available'); +if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.5', '<')) { + die('skip only for bundled libgd or external libgd >= 2.2.5'); +} +?> +--FILE-- +<?php +$im = imagecreatefrompng(__DIR__ . '/bug75124.png'); +var_dump(imageistruecolor($im)); +imagefilter($im, IMG_FILTER_GRAYSCALE); +for ($i = 0, $width = imagesx($im); $i < $width; $i ++) { + for ($j = 0, $height = imagesy($im); $j < $height; $j++) { + $color = imagecolorat($im, $i, $j); + $red = ($color >> 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 0000000..b5d5d1f Binary files /dev/null and b/ext/gd/tests/bug75124.png differ

« previous php.cvs (#99173) next »