Fix #69024: imagescale segfault with palette based image
authorChristoph M. Becker <cmb@php.net>
Mon, 13 Jul 2015 13:43:16 +0000 (15:43 +0200)
committerChristoph M. Becker <cmb@php.net>
Mon, 13 Jul 2015 13:43:16 +0000 (15:43 +0200)
imagescale(..., IMG_BICUBIC) is not supposed to work with palette images, so we
fix that by converting to true color if necessary. Basically the same fix has
already been applied to the external libgd[1].

[1] <https://github.com/libgd/libgd/commit/723ea520bed3b5854df87393c687323d3930edf3>

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

index ed2fc188f9f45528bcccb8f6f6928f7c44f11364..e2c9f0530640d342ac3762fd08afefc72a23ca54 100644 (file)
@@ -1059,6 +1059,11 @@ gdImagePtr gdImageScaleTwoPass(const gdImagePtr src, const unsigned int src_widt
        gdImagePtr tmp_im;
        gdImagePtr dst;
 
+       /* Convert to truecolor if it isn't; this code requires it. */
+       if (!src->trueColor) {
+               gdImagePaletteToTrueColor(src);
+       }
+
        tmp_im = gdImageCreateTrueColor(new_width, src_height);
        if (tmp_im == NULL) {
                return NULL;
diff --git a/ext/gd/tests/bug69024.phpt b/ext/gd/tests/bug69024.phpt
new file mode 100644 (file)
index 0000000..f2113fc
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Bug #69024 (imagescale segfault with palette based image)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+$im = imagecreate(256, 256);
+imagescale($im, 32, 32, IMG_BICUBIC);
+imagedestroy($im);
+echo "done\n";
+?>
+--EXPECT--
+done