com php-src: Fix #73213: Integer overflow in imageline() with antialiasing: NEWS ext/gd/libgd/gd.c ext/gd/tests/bug73213.phpt
ext/gd/tests/bug73213.png
| From: | Christoph Michael Becker | Date: | Fri, 30 Sep 2016 21:38:13 +0000 |
| Subject: | com php-src: Fix #73213: Integer overflow in imageline() with antialiasing: NEWS ext/gd/libgd/gd.c ext/gd/tests/bug73213.phpt ext/gd/tests/bug73213.png |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94807@lists.php.net to get a copy of this message | ||
Commit: 9acfb1a3a5268febb123b7e5fbd4eaf072c83537
Author: Christoph M. Becker <cmb@php.net> Fri, 30 Sep 2016 23:25:23 +0200
Committer: Christoph M. Becker <cmbecker69@gmx.de> Fri, 30 Sep 2016 23:38:13 +0200
Parents: c0219b323e0048440acbdd9ad74624c4bc33c335
Branches: PHP-5.6 PHP-7.0 PHP-7.1 master
Link: http://git.php.net/?p=php-src..git;a=commitdiff;h=9acfb1a3a5268febb123b7e5fbd4eaf072c83537
Log:
Fix #73213: Integer overflow in imageline() with antialiasing
We port the respective fixes <https://github.com/libgd/libgd/commit/eca37d620>
and <https://github.com/libgd/libgd/commit/837b7327>
to our bundled libgd.
Bugs:
https://bugs.php.net/73213
Changed paths:
M NEWS
M ext/gd/libgd/gd.c
A ext/gd/tests/bug73213.phpt
A ext/gd/tests/bug73213.png
Diff:
diff --git a/NEWS b/NEWS
index fae5b65...e9e4b94 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2016, PHP 5.6.28
+-GD:
+ . Fixed bug #73213 (Integer overflow in imageline() with antialiasing). (cmb)
+
- Standard:
. Fixed bug #73203 (passing additional_parameters causes mail to fail). (cmb)
diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c
index 0b4b42f..033d4fa 100644
--- a/ext/gd/libgd/gd.c
+++ b/ext/gd/libgd/gd.c
@@ -1298,7 +1298,7 @@ inline static void gdImageSetAAPixelColor(gdImagePtr im, int x, int y, int
color
void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col)
{
/* keep them as 32bits */
- long x, y, inc;
+ long x, y, inc, frac;
long dx, dy,tmp;
if (y1 < 0 && y2 < 0) {
@@ -1368,16 +1368,22 @@ void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col)
dx = x2 - x1;
dy = y2 - y1;
}
- x = x1 << 16;
- y = y1 << 16;
+ y = y1;
inc = (dy * 65536) / dx;
- while ((x >> 16) <= x2) {
- gdImageSetAAPixelColor(im, x >> 16, y >> 16, col, (y >> 8) & 0xFF);
- if ((y >> 16) + 1 < im->sy) {
- gdImageSetAAPixelColor(im, x >> 16, (y >> 16) + 1,col, (~y >> 8) & 0xFF);
+ frac = 0;
+ for (x = x1; x <= x2; x++) {
+ gdImageSetAAPixelColor(im, x, y, col, (frac >> 8) & 0xFF);
+ if (y + 1 < im->sy) {
+ gdImageSetAAPixelColor(im, x, y + 1, col, (~frac >> 8) & 0xFF);
+ }
+ frac += inc;
+ if (frac >= 65536) {
+ frac -= 65536;
+ y++;
+ } else if (frac < 0) {
+ frac += 65536;
+ y--;
}
- x += (1 << 16);
- y += inc;
}
} else {
if (dy < 0) {
@@ -1390,16 +1396,22 @@ void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col)
dx = x2 - x1;
dy = y2 - y1;
}
- x = x1 << 16;
- y = y1 << 16;
+ x = x1;
inc = (dx * 65536) / dy;
- while ((y>>16) <= y2) {
- gdImageSetAAPixelColor(im, x >> 16, y >> 16, col, (x >> 8) & 0xFF);
- if ((x >> 16) + 1 < im->sx) {
- gdImageSetAAPixelColor(im, (x >> 16) + 1, (y >> 16),col, (~x >> 8) &
0xFF);
+ frac = 0;
+ for (y = y1; y <= y2; y++) {
+ gdImageSetAAPixelColor(im, x, y, col, (frac >> 8) & 0xFF);
+ if (x + 1 < im->sx) {
+ gdImageSetAAPixelColor(im, x + 1, y, col, (~frac >> 8) & 0xFF);
+ }
+ frac += inc;
+ if (frac >= 65536) {
+ frac -= 65536;
+ x++;
+ } else if (frac < 0) {
+ frac += 65536;
+ x--;
}
- x += inc;
- y += (1<<16);
}
}
}
diff --git a/ext/gd/tests/bug73213.phpt b/ext/gd/tests/bug73213.phpt
new file mode 100644
index 0000000..86c4078
--- /dev/null
+++ b/ext/gd/tests/bug73213.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #73213 (Integer overflow in imageline() with antialiasing)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+require_once __DIR__ . DIRECTORY_SEPARATOR . 'func.inc';
+
+$im = imagecreatetruecolor(32768, 1);
+$black = imagecolorallocate($im, 0, 0, 0);
+imageantialias($im, true);
+
+imageline($im, 0,0, 32767,0, $black);
+
+test_image_equals_file(__DIR__ . DIRECTORY_SEPARATOR . 'bug73213.png', $im);
+?>
+===DONE===
+--EXPECT--
+The images are equal.
+===DONE===
diff --git a/ext/gd/tests/bug73213.png b/ext/gd/tests/bug73213.png
new file mode 100644
index 0000000..4cf0ed5
Binary files /dev/null and b/ext/gd/tests/bug73213.png differ