Skip to content

Commit 2c58605

Browse files
committed
Fix #79067: gdTransformAffineCopy() may use unitialized values
We port <libgd/libgd@7a06c16>.
1 parent c05a069 commit 2c58605

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ PHP NEWS
2424
- GD:
2525
. Fixed bug #78923 (Artifacts when convoluting image with transparency).
2626
(wilson chen)
27+
. Fixed bug #79067 (gdTransformAffineCopy() may use unitialized values). (cmb)
2728

2829
- Libxml:
2930
. Fixed bug #79029 (Use After Free's in XMLReader / XMLWriter). (Laruence)

ext/gd/libgd/gd_interpolation.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,7 +2334,7 @@ int gdTransformAffineGetImage(gdImagePtr *dst,
23342334
* src_area - Rectangular region to rotate in the src image
23352335
*
23362336
* Returns:
2337-
* GD_TRUE if the affine is rectilinear or GD_FALSE
2337+
* GD_TRUE on success or GD_FALSE on failure
23382338
*/
23392339
int gdTransformAffineCopy(gdImagePtr dst,
23402340
int dst_x, int dst_y,
@@ -2393,7 +2393,10 @@ int gdTransformAffineCopy(gdImagePtr dst,
23932393
end_y = bbox.height + (int) fabs(bbox.y);
23942394

23952395
/* Get inverse affine to let us work with destination -> source */
2396-
gdAffineInvert(inv, affine);
2396+
if (gdAffineInvert(inv, affine) == GD_FALSE) {
2397+
gdImageSetInterpolationMethod(src, interpolation_id_bak);
2398+
return GD_FALSE;
2399+
}
23972400

23982401
src_offset_x = src_region->x;
23992402
src_offset_y = src_region->y;

ext/gd/libgd/gd_matrix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int gdAffineApplyToPointF (gdPointFPtr dst, const gdPointFPtr src,
5555
* <gdAffineIdentity>
5656
*
5757
* Returns:
58-
* GD_TRUE if the affine is rectilinear or GD_FALSE
58+
* GD_TRUE on success or GD_FALSE on failure
5959
*/
6060
int gdAffineInvert (double dst[6], const double src[6])
6161
{

ext/gd/tests/bug79067.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #79067 (gdTransformAffineCopy() may use unitialized values)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$matrix = [1, 1, 1, 1, 1, 1];
10+
$src = imagecreatetruecolor(8, 8);
11+
var_dump(imageaffine($src, $matrix));
12+
?>
13+
--EXPECT--
14+
bool(false)

0 commit comments

Comments
 (0)