[Libreoffice-commits] core.git: tools/source
Caolán McNamara
caolanm at redhat.com
Fri Oct 27 15:37:30 UTC 2017
tools/source/generic/poly.cxx | 38 +++++++++++++++++++++++++++++---------
1 file changed, 29 insertions(+), 9 deletions(-)
New commits:
commit 3e2df29c520a7bc0c2cc4b37d42fb9bcd52da60f
Author: Caolán McNamara <caolanm at redhat.com>
Date: Fri Oct 27 14:52:49 2017 +0100
ofz#3791 Integer-overflow
Change-Id: I0b8258eaf676ee7291365aec10a7876833aba626
Reviewed-on: https://gerrit.libreoffice.org/43947
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/tools/source/generic/poly.cxx b/tools/source/generic/poly.cxx
index e7b9397ab734..c44c5ecf7b69 100644
--- a/tools/source/generic/poly.cxx
+++ b/tools/source/generic/poly.cxx
@@ -27,6 +27,7 @@
#include <tools/vcompat.hxx>
#include <tools/gen.hxx>
#include <poly.h>
+#include <o3tl/safeint.hxx>
#include <tools/line.hxx>
#include <tools/poly.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
@@ -628,12 +629,22 @@ Polygon::Polygon( const Point& rCenter, long nRadX, long nRadY )
{
if( nRadX && nRadY )
{
- sal_uInt16 nPoints = 0;
+ sal_uInt16 nPoints;
+
// Compute default (depends on size)
- nPoints = (sal_uInt16) MinMax(
- ( F_PI * ( 1.5 * ( nRadX + nRadY ) -
- sqrt( (double) labs( nRadX * nRadY ) ) ) ),
- 32, 256 );
+ long nRadXY;
+ const bool bOverflow = o3tl::checked_multiply(nRadX, nRadY, nRadXY);
+ if (!bOverflow)
+ {
+ nPoints = (sal_uInt16) MinMax(
+ ( F_PI * ( 1.5 * ( nRadX + nRadY ) -
+ sqrt( (double) labs(nRadXY) ) ) ),
+ 32, 256 );
+ }
+ else
+ {
+ nPoints = 256;
+ }
if( ( nRadX > 32 ) && ( nRadY > 32 ) && ( nRadX + nRadY ) < 8192 )
nPoints >>= 1;
@@ -683,10 +694,19 @@ Polygon::Polygon( const tools::Rectangle& rBound, const Point& rStart, const Poi
const long nRadY = aCenter.Y() - rBound.Top();
sal_uInt16 nPoints;
- nPoints = (sal_uInt16) MinMax(
- ( F_PI * ( 1.5 * ( nRadX + nRadY ) -
- sqrt( (double) labs( nRadX * nRadY ) ) ) ),
- 32, 256 );
+ long nRadXY;
+ const bool bOverflow = o3tl::checked_multiply(nRadX, nRadY, nRadXY);
+ if (!bOverflow)
+ {
+ nPoints = (sal_uInt16) MinMax(
+ ( F_PI * ( 1.5 * ( nRadX + nRadY ) -
+ sqrt( (double) labs(nRadXY) ) ) ),
+ 32, 256 );
+ }
+ else
+ {
+ nPoints = 256;
+ }
if( ( nRadX > 32 ) && ( nRadY > 32 ) && ( nRadX + nRadY ) < 8192 )
nPoints >>= 1;
More information about the Libreoffice-commits
mailing list