Skip to content

Commit c395c6e

Browse files
committed
iFixed bug #72446 - Integer Overflow in gdImagePaletteToTrueColor() resulting in heap overflow
1 parent b028cac commit c395c6e

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ PHP NEWS
1818
. Fixed bug #72339 (Integer Overflow in _gd2GetHeader() resulting in
1919
heap overflow). (Pierre)
2020
. Fixed bug #72407 (NULL Pointer Dereference at _gdScaleVert). (Stas)
21+
. Fixed bug #72446 (Integer Overflow in gdImagePaletteToTrueColor() resulting
22+
in heap overflow). (Pierre)
2123

2224
- mbstring:
2325
. Fixed bug #72402 (_php_mb_regex_ereg_replace_exec - double free). (Stas)

ext/gd/libgd/gd.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ gdImagePtr gdImageCreate (int sx, int sy)
133133
return NULL;
134134
}
135135

136+
if (overflow2(sizeof(unsigned char *), sx)) {
137+
return NULL;
138+
}
139+
136140
im = (gdImage *) gdCalloc(1, sizeof(gdImage));
137141

138142
/* Row-major ever since gd 1.3 */
@@ -1098,12 +1102,12 @@ void gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
10981102
int thick = im->thick;
10991103

11001104
if (color == gdAntiAliased) {
1101-
/*
1105+
/*
11021106
gdAntiAliased passed as color: use the much faster, much cheaper
11031107
and equally attractive gdImageAALine implementation. That
11041108
clips too, so don't clip twice.
11051109
*/
1106-
gdImageAALine(im, x1, y1, x2, y2, im->AA_color);
1110+
gdImageAALine(im, x1, y1, x2, y2, im->AA_color);
11071111
return;
11081112
}
11091113

@@ -1880,7 +1884,7 @@ void gdImageFill(gdImagePtr im, int x, int y, int nc)
18801884
return;
18811885
}
18821886

1883-
alphablending_bak = im->alphaBlendingFlag;
1887+
alphablending_bak = im->alphaBlendingFlag;
18841888
im->alphaBlendingFlag = 0;
18851889

18861890
if (nc==gdTiled){
@@ -1892,7 +1896,7 @@ void gdImageFill(gdImagePtr im, int x, int y, int nc)
18921896
wx2=im->sx;wy2=im->sy;
18931897
oc = gdImageGetPixel(im, x, y);
18941898
if (oc==nc || x<0 || x>wx2 || y<0 || y>wy2) {
1895-
im->alphaBlendingFlag = alphablending_bak;
1899+
im->alphaBlendingFlag = alphablending_bak;
18961900
return;
18971901
}
18981902

@@ -1955,7 +1959,7 @@ skip: for (x++; x<=x2 && (gdImageGetPixel(im, x, y)!=oc); x++);
19551959
efree(stack);
19561960

19571961
done:
1958-
im->alphaBlendingFlag = alphablending_bak;
1962+
im->alphaBlendingFlag = alphablending_bak;
19591963
}
19601964

19611965
static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc)
@@ -2061,7 +2065,7 @@ void gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
20612065

20622066
x1ul = x1 - half;
20632067
y1ul = y1 - half;
2064-
2068+
20652069
x2lr = x2 + half;
20662070
y2lr = y2 + half;
20672071

@@ -2259,7 +2263,7 @@ void gdImageCopyMerge (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int s
22592263
int tox, toy;
22602264
int ncR, ncG, ncB;
22612265
toy = dstY;
2262-
2266+
22632267
for (y = srcY; y < (srcY + h); y++) {
22642268
tox = dstX;
22652269
for (x = srcX; x < (srcX + w); x++) {
@@ -2356,7 +2360,7 @@ void gdImageCopyResized (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int
23562360
int colorMap[gdMaxColors];
23572361
/* Stretch vectors */
23582362
int *stx, *sty;
2359-
2363+
23602364
if (overflow2(sizeof(int), srcW)) {
23612365
return;
23622366
}
@@ -2901,7 +2905,7 @@ int gdAlphaBlend (int dst, int src) {
29012905
src_weight = gdAlphaTransparent - src_alpha;
29022906
dst_weight = (gdAlphaTransparent - dst_alpha) * src_alpha / gdAlphaMax;
29032907
tot_weight = src_weight + dst_weight;
2904-
2908+
29052909
/* -------------------------------------------------------------------- */
29062910
/* What red, green and blue result values will we use? */
29072911
/* -------------------------------------------------------------------- */

0 commit comments

Comments
 (0)