Skip to content

Commit 7a1aac3

Browse files
committed
Fixed bug #72227: imagescale out-of-bounds read
Ported from libgd/libgd@4f65a3e
1 parent 97eff7e commit 7a1aac3

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

ext/gd/libgd/gd_interpolation.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
downscaling using the fixed point implementations are usually much faster
4040
than the existing gdImageCopyResampled while having a similar or better
4141
quality.
42-
43-
For image rotations, the optimized versions have a lazy antialiasing for
42+
43+
For image rotations, the optimized versions have a lazy antialiasing for
4444
the edges of the images. For a much better antialiased result, the affine
4545
function is recommended.
4646
*/
@@ -633,7 +633,7 @@ static inline int _color_blend (const int dst, const int src)
633633
}
634634
}
635635

636-
static inline int _setEdgePixel(const gdImagePtr src, unsigned int x, unsigned int y, gdFixed coverage, const int bgColor)
636+
static inline int _setEdgePixel(const gdImagePtr src, unsigned int x, unsigned int y, gdFixed coverage, const int bgColor)
637637
{
638638
const gdFixed f_127 = gd_itofx(127);
639639
register int c = src->tpixels[y][x];
@@ -934,9 +934,6 @@ static inline LineContribType *_gdContributionsCalc(unsigned int line_size, unsi
934934
double dTotalWeight = 0.0;
935935
int iSrc;
936936

937-
res->ContribRow[u].Left = iLeft;
938-
res->ContribRow[u].Right = iRight;
939-
940937
/* Cut edge points to fit in filter window in case of spill-off */
941938
if (iRight - iLeft + 1 > windows_size) {
942939
if (iLeft < ((int)src_size - 1 / 2)) {
@@ -946,6 +943,9 @@ static inline LineContribType *_gdContributionsCalc(unsigned int line_size, unsi
946943
}
947944
}
948945

946+
res->ContribRow[u].Left = iLeft;
947+
res->ContribRow[u].Right = iRight;
948+
949949
for (iSrc = iLeft; iSrc <= iRight; iSrc++) {
950950
dTotalWeight += (res->ContribRow[u].Weights[iSrc-iLeft] = scale_f_d * (*pFilter)(scale_f_d * (dCenter - (double)iSrc)));
951951
}
@@ -2273,7 +2273,7 @@ int gdTransformAffineGetImage(gdImagePtr *dst,
22732273
if (!src->trueColor) {
22742274
gdImagePaletteToTrueColor(src);
22752275
}
2276-
2276+
22772277
/* Translate to dst origin (0,0) */
22782278
gdAffineTranslate(m, -bbox.x, -bbox.y);
22792279
gdAffineConcat(m, affine, m);
@@ -2332,7 +2332,7 @@ int gdTransformAffineCopy(gdImagePtr dst,
23322332
if (src->interpolation_id == GD_BILINEAR_FIXED || src->interpolation_id == GD_BICUBIC_FIXED || src->interpolation_id == GD_NEAREST_NEIGHBOUR) {
23332333
interpolation_id_bak = src->interpolation_id;
23342334
interpolation_bak = src->interpolation;
2335-
2335+
23362336
gdImageSetInterpolationMethod(src, GD_BICUBIC);
23372337
}
23382338

ext/gd/tests/bug72227.phpt

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

0 commit comments

Comments
 (0)