Browse Source

Merge branch 'PHP-7.1' into PHP-7.2

* PHP-7.1:
  Fixed bug #75124 (gdImageGrayScale() may produce colors)
pull/2708/merge
Christoph M. Becker 9 years ago
parent
commit
1aeafb7d4a
  1. 1
      NEWS
  2. 7
      ext/gd/libgd/gd_filter.c
  3. 31
      ext/gd/tests/bug75124.phpt
  4. BIN
      ext/gd/tests/bug75124.png

1
NEWS

@ -11,6 +11,7 @@ PHP NEWS
- GD:
. Fixed bug #75111 (Memory disclosure or DoS via crafted .bmp image). (cmb)
. Fixed bug #75124 (gdImageGrayScale() may produce colors). (cmb)
- Intl:
. Fixed bug #75090 (IntlGregorianCalendar doesn't have constants from parent

7
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;
}

31
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===

BIN
ext/gd/tests/bug75124.png

After

Width: 36  |  Height: 33  |  Size: 2.4 KiB

Loading…
Cancel
Save