Skip to content

Commit fcda8fa

Browse files
committed
Fix GH-20660: imageellipse()/imagefilledellipse() overflow
1 parent 1f1147a commit fcda8fa

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

ext/gd/libgd/gd.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,13 @@ void gdImageEllipse(gdImagePtr im, int mx, int my, int w, int h, int c)
17231723
b=h>>1;
17241724
gdImageSetPixel(im,mx+a, my, c);
17251725
gdImageSetPixel(im,mx-a, my, c);
1726+
if (a > (INT64_MAX >> 1) / b / b) {
1727+
return;
1728+
}
1729+
1730+
if (b > (INT64_MAX >> 1) / a / a) {
1731+
return;
1732+
}
17261733
mx1 = mx-a;my1 = my;
17271734
mx2 = mx+a;my2 = my;
17281735

@@ -1762,6 +1769,13 @@ void gdImageFilledEllipse (gdImagePtr im, int mx, int my, int w, int h, int c)
17621769

17631770
a=w>>1;
17641771
b=h>>1;
1772+
if (a > (INT64_MAX >> 1) / b / b) {
1773+
return;
1774+
}
1775+
1776+
if (b > (INT64_MAX >> 1) / a / a) {
1777+
return;
1778+
}
17651779

17661780
for (x = mx-a; x <= mx+a; x++) {
17671781
gdImageSetPixel(im, x, my, c);

ext/gd/tests/gh20660-2.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
GH-20660 (imagefilleellipse() overflow)
3+
--EXTENSIONS--
4+
gd
5+
--SKIPIF--
6+
<?php if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); ?>
7+
--FILE--
8+
<?php
9+
$im = imagecreate(8, 8);
10+
imageellipse($im, 255, 255, "1234567890", 64, 0);
11+
imagefilledellipse($im, 255, 255, "1234567890", 64, 0);
12+
echo "OK";
13+
?>
14+
--EXPECT--
15+
OK

ext/gd/tests/gh20660.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-20660 (imageellipse() overflow)
3+
--EXTENSIONS--
4+
gd
5+
--SKIPIF--
6+
<?php if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); ?>
7+
--FILE--
8+
<?php
9+
$im = imagecreate(8, 8);
10+
imageellipse($im, 255, 255, "1234567890", 64, 0);
11+
echo "OK";
12+
?>
13+
--EXPECT--
14+
OK

0 commit comments

Comments
 (0)