From e1a2ac1900f2f16ec48fb4840a6b7965a8373c2b Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Wed, 23 Jan 2013 19:51:28 -0500 Subject: [PATCH] [base] Fix integer overflow. * src/base/ftoutln.c (FT_Outline_Get_Orientation): Scale the coordinates down to avoid overflow. --- ChangeLog | 7 +++++++ src/base/ftoutln.c | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 01db3c4b8..7b2767ae5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2013-01-23 Alexei Podtelezhnikov + + [base] Fix integer overflow. + + * src/base/ftoutln.c (FT_Outline_Get_Orientation): Scale the + coordinates down to avoid overflow. + 2013-01-23 Alexei Podtelezhnikov [base] Split out MSB function. 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; }