[Libreoffice-commits] core.git: editeng/source include/tools sw/source

Caolán McNamara caolanm at redhat.com
Tue Oct 31 23:26:21 UTC 2017


 editeng/source/uno/unoipset.cxx |   16 ++++++----------
 include/tools/helpers.hxx       |   18 +++++++++++++++++-
 sw/source/filter/xml/xmlimp.cxx |   20 +-------------------
 3 files changed, 24 insertions(+), 30 deletions(-)

New commits:
commit 013618308c2d24702de18c12922931b130b6fade
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Oct 31 08:54:42 2017 +0000

    ofz#3934 Integer-overflow
    
    Change-Id: I2c58cca6f01d7c50244dfec6acdfaa988cdbaa07
    Reviewed-on: https://gerrit.libreoffice.org/44102
    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/editeng/source/uno/unoipset.cxx b/editeng/source/uno/unoipset.cxx
index cc2a5c6c1861..8d4b41e4ffb1 100644
--- a/editeng/source/uno/unoipset.cxx
+++ b/editeng/source/uno/unoipset.cxx
@@ -19,9 +19,8 @@
 
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <svl/eitem.hxx>
-
 #include <svl/itemprop.hxx>
-
+#include <tools/helpers.hxx>
 #include <editeng/unoipset.hxx>
 #include <editeng/editids.hrc>
 #include <editeng/editeng.hxx>
@@ -272,9 +271,6 @@ uno::Reference< beans::XPropertySetInfo > const &  SvxItemPropertySet::getProper
 #ifndef TWIPS_TO_MM
 #define TWIPS_TO_MM(val) ((val * 127 + 36) / 72)
 #endif
-#ifndef MM_TO_TWIPS
-#define MM_TO_TWIPS(val) ((val * 72 + 63) / 127)
-#endif
 
 /** converts the given any with a metric to 100th/mm if needed */
 void SvxUnoConvertToMM( const MapUnit eSourceMapUnit, uno::Any & rMetric ) throw()
@@ -324,19 +320,19 @@ void SvxUnoConvertFromMM( const MapUnit eDestinationMapUnit, uno::Any & rMetric
             switch( rMetric.getValueTypeClass() )
             {
                 case uno::TypeClass_BYTE:
-                    rMetric <<= (sal_Int8)(MM_TO_TWIPS(*o3tl::forceAccess<sal_Int8>(rMetric)));
+                    rMetric <<= (sal_Int8)(sanitiseMm100ToTwip(*o3tl::forceAccess<sal_Int8>(rMetric)));
                     break;
                 case uno::TypeClass_SHORT:
-                    rMetric <<= (sal_Int16)(MM_TO_TWIPS(*o3tl::forceAccess<sal_Int16>(rMetric)));
+                    rMetric <<= (sal_Int16)(sanitiseMm100ToTwip(*o3tl::forceAccess<sal_Int16>(rMetric)));
                     break;
                 case uno::TypeClass_UNSIGNED_SHORT:
-                    rMetric <<= (sal_uInt16)(MM_TO_TWIPS(*o3tl::forceAccess<sal_uInt16>(rMetric)));
+                    rMetric <<= (sal_uInt16)(sanitiseMm100ToTwip(*o3tl::forceAccess<sal_uInt16>(rMetric)));
                     break;
                 case uno::TypeClass_LONG:
-                    rMetric <<= (sal_Int32)(MM_TO_TWIPS(*o3tl::forceAccess<sal_Int32>(rMetric)));
+                    rMetric <<= (sal_Int32)(sanitiseMm100ToTwip(*o3tl::forceAccess<sal_Int32>(rMetric)));
                     break;
                 case uno::TypeClass_UNSIGNED_LONG:
-                    rMetric <<= (sal_uInt32)(MM_TO_TWIPS(*o3tl::forceAccess<sal_uInt32>(rMetric)));
+                    rMetric <<= (sal_uInt32)(sanitiseMm100ToTwip(*o3tl::forceAccess<sal_uInt32>(rMetric)));
                     break;
                 default:
                     OSL_FAIL("AW: Missing unit translation to 100th mm!");
diff --git a/include/tools/helpers.hxx b/include/tools/helpers.hxx
index 30064cf93fc6..8325f095bad8 100644
--- a/include/tools/helpers.hxx
+++ b/include/tools/helpers.hxx
@@ -11,7 +11,7 @@
 
 #include <sal/config.h>
 #include <sal/types.h>
-
+#include <o3tl/safeint.hxx>
 #include <cassert>
 #include <type_traits>
 
@@ -55,6 +55,22 @@ inline long FRound( double fVal )
     return fVal > 0.0 ? static_cast<long>( fVal + 0.5 ) : -static_cast<long>( -fVal + 0.5 );
 }
 
+// return (n >= 0)? (n*72+63)/127: (n*72-63)/127;
+inline sal_Int64 sanitiseMm100ToTwip(sal_Int64 n)
+{
+    if (n >= 0)
+    {
+        if (o3tl::checked_multiply<sal_Int64>(n, 72, n) || o3tl::checked_add<sal_Int64>(n, 63, n))
+            n = SAL_MAX_INT64;
+    }
+    else
+    {
+        if (o3tl::checked_multiply<sal_Int64>(n, 72, n) || o3tl::checked_sub<sal_Int64>(n, 63, n))
+            n = SAL_MIN_INT64;
+    }
+    return n / 127;
+}
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
index f2f583fbf63e..f46cf200a416 100644
--- a/sw/source/filter/xml/xmlimp.cxx
+++ b/sw/source/filter/xml/xmlimp.cxx
@@ -70,6 +70,7 @@
 #include <xmloff/xmluconv.hxx>
 #include <unotools/saveopt.hxx>
 #include <unotools/streamwrap.hxx>
+#include <tools/helpers.hxx>
 #include <tools/diagnose_ex.h>
 
 #include <vcl/svapp.hxx>
@@ -972,25 +973,6 @@ SvXMLImportContext *SwXMLImport::CreateFontDeclsContext(
     return pFSContext;
 }
 
-namespace
-{
-    // return (n >= 0)? (n*72+63)/127: (n*72-63)/127;
-    sal_Int64 sanitiseMm100ToTwip(sal_Int64 n)
-    {
-        if (n >= 0)
-        {
-            if (o3tl::checked_multiply<sal_Int64>(n, 72, n) || o3tl::checked_add<sal_Int64>(n, 63, n))
-                n = SAL_MAX_INT64;
-        }
-        else
-        {
-            if (o3tl::checked_multiply<sal_Int64>(n, 72, n) || o3tl::checked_sub<sal_Int64>(n, 63, n))
-                n = SAL_MIN_INT64;
-        }
-        return n / 127;
-    }
-}
-
 void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps)
 {
     if (IsInsertMode() || IsStylesOnlyMode() || IsBlockMode() || m_bOrganizerMode || !GetModel().is() )


More information about the Libreoffice-commits mailing list