]> granicus.if.org Git - php/commitdiff
Fix #66005: imagecopy does not support 1bit transparency on truecolor images
authorChristoph M. Becker <cmbecker69@gmx.de>
Sun, 21 Aug 2016 14:07:34 +0000 (16:07 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Sun, 21 Aug 2016 14:08:57 +0000 (16:08 +0200)
We must not copy transparent pixels, see
<https://github.com/libgd/libgd/commit/daac285c>.

NEWS
ext/gd/libgd/gd.c
ext/gd/tests/bug66005.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 608881ae6588deb10a30453b1df5f4caaf33825a..676760ef6ffe80949c0dcb54541def176ef8f9ea 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,10 @@ PHP                                                                        NEWS
   . Fixed bug #70195 (Cannot upload file using ftp_put to FTPES with
     require_ssl_reuse). (Benedict Singer)
 
+- GD:
+  . Fixed bug #66005 (imagecopy does not support 1bit transparency on truecolor
+    images). (cmb)
+
 - JSON:
   . Fixed bug #72787 (json_decode reads out of bounds). (Jakub Zelenka)
 
index 299c432afacd31ca70d7e009f0ce3a9570bd8b16..364697338e95ceb978196db24e721ce477f9d384 100644 (file)
@@ -2247,7 +2247,9 @@ void gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX,
                        for (y = 0; (y < h); y++) {
                                for (x = 0; (x < w); x++) {
                                        int c = gdImageGetTrueColorPixel (src, srcX + x, srcY + y);
-                                       gdImageSetPixel (dst, dstX + x, dstY + y, c);
+                                       if (c != src->transparent) {
+                                               gdImageSetPixel (dst, dstX + x, dstY + y, c);
+                                       }
                                }
                        }
                } else {
diff --git a/ext/gd/tests/bug66005.phpt b/ext/gd/tests/bug66005.phpt
new file mode 100644 (file)
index 0000000..a01c5c3
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Bug #66005 (imagecopy does not support 1bit transparency on truecolor images)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+$dest = imagecreatetruecolor(150, 50);
+$transparent = imagecolorallocatealpha($dest, 255, 255, 255, 127);
+imagealphablending($dest, false);
+imagefill($dest, 1, 1, $transparent);
+imagesavealpha($dest, true);
+
+// Palette image with transparent color
+$png_palette = imagecreatefromstring(base64_decode('iVBORw0KGgoAAAANSUhEUgAAADIAAAAyAgMAAABjUWAiAAAACVBMVEUAAAD/AAD///9nGWQeAAAAAXRSTlMAQObYZgAAAEFJREFUKM9jYBimIASZIxoagOAwhoaGInisQJ4DksJQJKWoPCAnNIQYHsgChBX4eMSbiddlqH5A9R+q39HCZWgDAFxFGyOrmguhAAAAAElFTkSuQmCCPHP'));
+
+// 24 bit with transparent color
+$png_24 = imagecreatefromstring(base64_decode('iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAABnRSTlMAAAAAAABupgeRAAAAVklEQVRYw+3UQQqAMBAEwf3/p9eTBxEPiWAmWMU8oGFJqgAAuOpzWTX3xQUti+uRJTZ9V5aY1bOTFZLV7yZr9zt6ibv/qPXfrMpsGipbIy7oqQ8AYJED1plDy5PCu2sAAAAASUVORK5CYII='));
+
+// 32 bit with full alpha channel
+$png_full = imagecreatefromstring(base64_decode('iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAXklEQVRo3u3XMQrAIBBFwb3/pU2VwiJNIvjdzMD2PlBwqwAAAGajatxz9OGf5viA+KA3EXExXyKiYlqErIiIiBGSFLIyYmuMkO7Xy2MX4ovS/ONoH7Eh/m1nBwCASBe3VYeVaAy8PwAAAABJRU5ErkJggg=='));
+
+imagecopy($dest, $png_palette, 0, 0, 0, 0, 50, 50);
+imagecopy($dest, $png_24, 50, 0, 0, 0, 50, 50);
+imagecopy($dest, $png_full, 100, 0, 0, 0, 50, 50);
+
+ob_start();
+imagegd($dest);
+echo md5(ob_get_clean()), PHP_EOL;
+?>
+==DONE==
+--EXPECT--
+9b36049de01006b367efd433f1689043
+==DONE==