Skip to content

Commit e9ac895

Browse files
committed
Fix bug #72298 pass2_no_dither out-of-bounds access
1 parent 7722455 commit e9ac895

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

ext/gd/libgd/gd_topal.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* If it is not working, it's not Thomas G. Lane's fault.
4444
*/
4545

46-
/*
46+
/*
4747
SETTING THIS ONE CAUSES STRIPED IMAGE
4848
to be done: solve this
4949
#define ORIGINAL_LIB_JPEG_REVERSE_ODD_ROWS
@@ -152,7 +152,7 @@
152152
* color space, and repeatedly splits the "largest" remaining box until we
153153
* have as many boxes as desired colors. Then the mean color in each
154154
* remaining box becomes one of the possible output colors.
155-
*
155+
*
156156
* The second pass over the image maps each input pixel to the closest output
157157
* color (optionally after applying a Floyd-Steinberg dithering correction).
158158
* This mapping is logically trivial, but making it go fast enough requires
@@ -1320,16 +1320,16 @@ pass2_no_dither (j_decompress_ptr cinfo,
13201320
#else
13211321
r = gdTrueColorGetRed (*inptr);
13221322
g = gdTrueColorGetGreen (*inptr);
1323-
/*
1323+
/*
13241324
2.0.24: inptr must not be incremented until after
1325-
transparency check, if any. Thanks to "Super Pikeman."
1325+
transparency check, if any. Thanks to "Super Pikeman."
13261326
*/
13271327
b = gdTrueColorGetBlue (*inptr);
13281328

13291329
/* If the pixel is transparent, we assign it the palette index that
13301330
* will later be added at the end of the palette as the transparent
13311331
* index. */
1332-
if ((oim->transparent >= 0) && (oim->transparent == *(inptr - 1)))
1332+
if ((oim->transparent >= 0) && (oim->transparent == *inptr))
13331333
{
13341334
*outptr++ = nim->colorsTotal;
13351335
inptr++;
@@ -1795,7 +1795,7 @@ static void gdImageTrueColorToPaletteBody (gdImagePtr oim, int dither, int color
17951795
}
17961796
} else {
17971797
nim = oim;
1798-
}
1798+
}
17991799
if (!oim->trueColor)
18001800
{
18011801
/* (Almost) nothing to do! */
@@ -2004,7 +2004,7 @@ static void gdImageTrueColorToPaletteBody (gdImagePtr oim, int dither, int color
20042004
}
20052005

20062006
/* Success! Get rid of the truecolor image data. */
2007-
if (!cimP) {
2007+
if (!cimP) {
20082008
oim->trueColor = 0;
20092009
/* Junk the truecolor pixels */
20102010
for (i = 0; i < oim->sy; i++)

ext/gd/tests/bug72298.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #72298: pass2_no_dither out-of-bounds access
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die("skip gd extension not available\n");
6+
?>
7+
--FILE--
8+
<?php
9+
$img = imagecreatetruecolor (1 , 1);
10+
imagecolortransparent($img, 0);
11+
imagetruecolortopalette($img, false, 4);
12+
?>
13+
DONE
14+
--EXPECT--
15+
DONE

0 commit comments

Comments
 (0)