summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Podtelezhnikov <apodtele@gmail.com>2013-01-23 19:51:28 -0500
committerAlexei Podtelezhnikov <apodtele@gmail.com>2013-01-23 19:51:28 -0500
commite1a2ac1900f2f16ec48fb4840a6b7965a8373c2b (patch)
tree9ce3ac5c61f8887e8215ca007769ff55913f767d
parent869fb8c49ddf292d6daf4826172a308973d3e11f (diff)
downloadfreetype2-e1a2ac1900f2f16ec48fb4840a6b7965a8373c2b.tar.gz
[base] Fix integer overflow.
* src/base/ftoutln.c (FT_Outline_Get_Orientation): Scale the coordinates down to avoid overflow.
-rw-r--r--ChangeLog7
-rw-r--r--src/base/ftoutln.c13
2 files changed, 19 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 01db3c4b8..7b2767ae5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2013-01-23 Alexei Podtelezhnikov <apodtele@gmail.com>
+ [base] Fix integer overflow.
+
+ * src/base/ftoutln.c (FT_Outline_Get_Orientation): Scale the
+ coordinates down to avoid overflow.
+
+2013-01-23 Alexei Podtelezhnikov <apodtele@gmail.com>
+
[base] Split out MSB function.
* src/base/fttrigon.c (ft_trig_prenorm): Borrow from here.
diff --git a/src/base/ftoutln.c b/src/base/ftoutln.c
index 27aba015a..875968c6c 100644
--- a/src/base/ftoutln.c
+++ b/src/base/ftoutln.c
@@ -1009,6 +1009,8 @@
FT_EXPORT_DEF( FT_Orientation )
FT_Outline_Get_Orientation( FT_Outline* outline )
{
+ FT_BBox cbox;
+ FT_Int xshift, yshift;
FT_Vector* points;
FT_Vector v_prev, v_cur;
FT_Int c, n, first;
@@ -1023,6 +1025,14 @@
/* cubic or quadratic curves, this test deals with the polygon */
/* only which is spanned up by the control points. */
+ FT_Outline_Get_CBox( outline, &cbox );
+
+ xshift = FT_MSB( FT_ABS( cbox.xMax ) | FT_ABS( cbox.xMin ) ) - 14;
+ xshift = FT_MAX( xshift, 0 );
+
+ yshift = FT_MSB( cbox.yMax - cbox.yMin ) - 14;
+ yshift = FT_MAX( yshift, 0 );
+
points = outline->points;
first = 0;
@@ -1036,7 +1046,8 @@
for ( n = first; n <= last; n++ )
{
v_cur = points[n];
- area += ( v_cur.y - v_prev.y ) * ( v_cur.x + v_prev.x );
+ area += ( ( v_cur.y - v_prev.y ) >> yshift ) *
+ ( ( v_cur.x + v_prev.x ) >> xshift );
v_prev = v_cur;
}