1
0
mirror of https://github.com/php/php-src.git synced 2026-03-28 10:12:18 +01:00

Merge branch 'PHP-7.2' into PHP-7.3

* PHP-7.2:
  Fix #73281: imagescale(…, IMG_BILINEAR_FIXED) can cause black border
This commit is contained in:
Christoph M. Becker
2019-01-10 16:14:56 +01:00
3 changed files with 57 additions and 81 deletions

2
NEWS
View File

@@ -19,6 +19,8 @@ PHP NEWS
application/octet-stream). (Anatol)
- GD:
. Fixed bug #73281 (imagescale(…, IMG_BILINEAR_FIXED) can cause black border).
(cmb)
. Fixed bug #77272 (imagescale() may return image resource on failure). (cmb)
. Fixed bug #77391 (1bpp BMPs may fail to be loaded). (Romain Déoux, cmb)

View File

@@ -662,43 +662,7 @@ static inline int getPixelOverflowTC(gdImagePtr im, const int x, const int y, co
}
return c;
} else {
register int border = 0;
if (y < im->cy1) {
border = im->tpixels[0][im->cx1];
goto processborder;
}
if (y < im->cy1) {
border = im->tpixels[0][im->cx1];
goto processborder;
}
if (y > im->cy2) {
if (x >= im->cx1 && x <= im->cx1) {
border = im->tpixels[im->cy2][x];
goto processborder;
} else {
return gdTrueColorAlpha(0, 0, 0, 127);
}
}
/* y is bound safe at this point */
if (x < im->cx1) {
border = im->tpixels[y][im->cx1];
goto processborder;
}
if (x > im->cx2) {
border = im->tpixels[y][im->cx2];
}
processborder:
if (border == im->transparent) {
return gdTrueColorAlpha(0, 0, 0, 127);
} else{
return gdTrueColorAlpha(gdTrueColorGetRed(border), gdTrueColorGetGreen(border), gdTrueColorGetBlue(border), 127);
}
return bgColor;
}
}
@@ -713,42 +677,7 @@ static inline int getPixelOverflowPalette(gdImagePtr im, const int x, const int
}
return colorIndex2RGBA(c);
} else {
register int border = 0;
if (y < im->cy1) {
border = gdImageGetPixel(im, im->cx1, 0);
goto processborder;
}
if (y < im->cy1) {
border = gdImageGetPixel(im, im->cx1, 0);
goto processborder;
}
if (y > im->cy2) {
if (x >= im->cx1 && x <= im->cx1) {
border = gdImageGetPixel(im, x, im->cy2);
goto processborder;
} else {
return gdTrueColorAlpha(0, 0, 0, 127);
}
}
/* y is bound safe at this point */
if (x < im->cx1) {
border = gdImageGetPixel(im, im->cx1, y);
goto processborder;
}
if (x > im->cx2) {
border = gdImageGetPixel(im, im->cx2, y);
}
processborder:
if (border == im->transparent) {
return gdTrueColorAlpha(0, 0, 0, 127);
} else{
return colorIndex2RGBcustomA(border, 127);
}
return bgColor;
}
}
@@ -1306,11 +1235,11 @@ static gdImagePtr gdImageScaleBilinearPalette(gdImagePtr im, const unsigned int
f_b1, f_b2, f_b3, f_b4,
f_a1, f_a2, f_a3, f_a4;
/* zero for the background color, nothig gets outside anyway */
/* 0 for bgColor; (n,m) is supposed to be valid anyway */
pixel1 = getPixelOverflowPalette(im, n, m, 0);
pixel2 = getPixelOverflowPalette(im, n + 1, m, 0);
pixel3 = getPixelOverflowPalette(im, n, m + 1, 0);
pixel4 = getPixelOverflowPalette(im, n + 1, m + 1, 0);
pixel2 = getPixelOverflowPalette(im, n + 1, m, pixel1);
pixel3 = getPixelOverflowPalette(im, n, m + 1, pixel1);
pixel4 = getPixelOverflowPalette(im, n + 1, m + 1, pixel1);
f_r1 = gd_itofx(gdTrueColorGetRed(pixel1));
f_r2 = gd_itofx(gdTrueColorGetRed(pixel2));
@@ -1398,11 +1327,11 @@ static gdImagePtr gdImageScaleBilinearTC(gdImagePtr im, const unsigned int new_w
f_b1, f_b2, f_b3, f_b4,
f_a1, f_a2, f_a3, f_a4;
dwSrcTotalOffset = m + n;
/* 0 for bgColor, nothing gets outside anyway */
/* 0 for bgColor; (n,m) is supposed to be valid anyway */
pixel1 = getPixelOverflowTC(im, n, m, 0);
pixel2 = getPixelOverflowTC(im, n + 1, m, 0);
pixel3 = getPixelOverflowTC(im, n, m + 1, 0);
pixel4 = getPixelOverflowTC(im, n + 1, m + 1, 0);
pixel2 = getPixelOverflowTC(im, n + 1, m, pixel1);
pixel3 = getPixelOverflowTC(im, n, m + 1, pixel1);
pixel4 = getPixelOverflowTC(im, n + 1, m + 1, pixel1);
f_r1 = gd_itofx(gdTrueColorGetRed(pixel1));
f_r2 = gd_itofx(gdTrueColorGetRed(pixel2));

View File

@@ -0,0 +1,45 @@
--TEST--
Bug #73281 (imagescale(…, IMG_BILINEAR_FIXED) can cause black border)
--SKIPIF--
<?php
if (!extension_loaded('gd')) die('skip gd extension not available');
if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.3', '<=')) die('skip upstream fix not yet released');
?>
--FILE--
<?php
$coordinates = [[0, 0], [0, 199], [199, 199], [199, 0]];
$src = imagecreatetruecolor(100, 100);
$white = imagecolorallocate($src, 255, 255, 255);
imagefilledrectangle($src, 0,0, 99,99, $white);
$dst = imagescale($src, 200, 200, IMG_BILINEAR_FIXED);
echo "truecolor source\n";
foreach ($coordinates as $coordinate) {
list($x, $y) = $coordinate;
printf("%3d, %3d: %x\n", $x, $y, imagecolorat($dst, $x, $y));
}
$src = imagecreate(100, 100);
$white = imagecolorallocate($src, 255, 255, 255);
imagefilledrectangle($src, 0,0, 99,99, $white);
$dst = imagescale($src, 200, 200, IMG_BILINEAR_FIXED);
echo "\npalette source\n";
foreach ($coordinates as $coordinate) {
list($x, $y) = $coordinate;
printf("%3d, %3d: %x\n", $x, $y, imagecolorat($dst, $x, $y));
}
?>
===DONE===
--EXPECT--
truecolor source
0, 0: ffffff
0, 199: ffffff
199, 199: ffffff
199, 0: ffffff
palette source
0, 0: ffffff
0, 199: ffffff
199, 199: ffffff
199, 0: ffffff
===DONE===