Skip to content

Commit

Permalink
fix #72512, invalid read or write for palette image when invalid tran…
Browse files Browse the repository at this point in the history
…sparent index is used

Conflicts:
	ext/gd/libgd/gd.c
  • Loading branch information
pierrejoye authored and smalyshev committed Jul 19, 2016
1 parent 33c1a55 commit 928aecc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ext/gd/libgd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,11 @@ void gdImageColorTransparent (gdImagePtr im, int color)
if (color < 0) {
return;
}

if (!im->trueColor) {
if((color >= gdMaxColors)) {
if((color >= im->colorsTotal)) {
return;
}
/* Make the old transparent color opaque again */
if (im->transparent != -1) {
im->alpha[im->transparent] = gdAlphaOpaque;
}
Expand Down
8 changes: 7 additions & 1 deletion ext/gd/libgd/gd_interpolation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,13 @@ static gdImagePtr gdImageScaleBilinearPalette(gdImagePtr im, const unsigned int
if (new_img == NULL) {
return NULL;
}
new_img->transparent = gdTrueColorAlpha(im->red[transparent], im->green[transparent], im->blue[transparent], im->alpha[transparent]);

if (transparent < 0) {
/* uninitialized */
new_img->transparent = -1;
} else {
new_img->transparent = gdTrueColorAlpha(im->red[transparent], im->green[transparent], im->blue[transparent], im->alpha[transparent]);
}

for (i=0; i < _height; i++) {
long j;
Expand Down
17 changes: 17 additions & 0 deletions ext/gd/tests/bug72512.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Bug #19366 (gdimagefill() function crashes (fixed in bundled libgd))
--SKIPIF--
<?php
if (!extension_loaded('gd')) die("skip gd extension not available\n");
?>
--FILE--
<?php
$img = imagecreatetruecolor(100, 100);
imagecolortransparent($img, -1000000);
imagetruecolortopalette($img, TRUE, 3);
imagecolortransparent($img, 9);
echo "OK";
?>
--EXPECT--
OK

0 comments on commit 928aecc

Please sign in to comment.