Skip to content

Commit 9eb5bbd

Browse files
committed
Fix #66005: imagecopy does not support 1bit transparency on truecolor images
We must not copy transparent pixels, see <libgd/libgd@daac285c>.
1 parent 226e21b commit 9eb5bbd

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ PHP NEWS
1313
. Fixed bug #70195 (Cannot upload file using ftp_put to FTPES with
1414
require_ssl_reuse). (Benedict Singer)
1515

16+
- GD:
17+
. Fixed bug #66005 (imagecopy does not support 1bit transparency on truecolor
18+
images). (cmb)
19+
1620
- JSON:
1721
. Fixed bug #72787 (json_decode reads out of bounds). (Jakub Zelenka)
1822

ext/gd/libgd/gd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,9 @@ void gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX,
22472247
for (y = 0; (y < h); y++) {
22482248
for (x = 0; (x < w); x++) {
22492249
int c = gdImageGetTrueColorPixel (src, srcX + x, srcY + y);
2250-
gdImageSetPixel (dst, dstX + x, dstY + y, c);
2250+
if (c != src->transparent) {
2251+
gdImageSetPixel (dst, dstX + x, dstY + y, c);
2252+
}
22512253
}
22522254
}
22532255
} else {

ext/gd/tests/bug66005.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Bug #66005 (imagecopy does not support 1bit transparency on truecolor images)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$dest = imagecreatetruecolor(150, 50);
10+
$transparent = imagecolorallocatealpha($dest, 255, 255, 255, 127);
11+
imagealphablending($dest, false);
12+
imagefill($dest, 1, 1, $transparent);
13+
imagesavealpha($dest, true);
14+
15+
// Palette image with transparent color
16+
$png_palette = imagecreatefromstring(base64_decode('iVBORw0KGgoAAAANSUhEUgAAADIAAAAyAgMAAABjUWAiAAAACVBMVEUAAAD/AAD///9nGWQeAAAAAXRSTlMAQObYZgAAAEFJREFUKM9jYBimIASZIxoagOAwhoaGInisQJ4DksJQJKWoPCAnNIQYHsgChBX4eMSbiddlqH5A9R+q39HCZWgDAFxFGyOrmguhAAAAAElFTkSuQmCCPHP'));
17+
18+
// 24 bit with transparent color
19+
$png_24 = imagecreatefromstring(base64_decode('iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAABnRSTlMAAAAAAABupgeRAAAAVklEQVRYw+3UQQqAMBAEwf3/p9eTBxEPiWAmWMU8oGFJqgAAuOpzWTX3xQUti+uRJTZ9V5aY1bOTFZLV7yZr9zt6ibv/qPXfrMpsGipbIy7oqQ8AYJED1plDy5PCu2sAAAAASUVORK5CYII='));
20+
21+
// 32 bit with full alpha channel
22+
$png_full = imagecreatefromstring(base64_decode('iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAXklEQVRo3u3XMQrAIBBFwb3/pU2VwiJNIvjdzMD2PlBwqwAAAGajatxz9OGf5viA+KA3EXExXyKiYlqErIiIiBGSFLIyYmuMkO7Xy2MX4ovS/ONoH7Eh/m1nBwCASBe3VYeVaAy8PwAAAABJRU5ErkJggg=='));
23+
24+
imagecopy($dest, $png_palette, 0, 0, 0, 0, 50, 50);
25+
imagecopy($dest, $png_24, 50, 0, 0, 0, 50, 50);
26+
imagecopy($dest, $png_full, 100, 0, 0, 0, 50, 50);
27+
28+
ob_start();
29+
imagegd($dest);
30+
echo md5(ob_get_clean()), PHP_EOL;
31+
?>
32+
==DONE==
33+
--EXPECT--
34+
9b36049de01006b367efd433f1689043
35+
==DONE==

0 commit comments

Comments
 (0)