diff options
-rw-r--r-- | filter/source/graphicfilter/icgm/class1.cxx | 6 | ||||
-rw-r--r-- | filter/source/graphicfilter/icgm/class4.cxx | 9 | ||||
-rw-r--r-- | include/o3tl/safeint.hxx | 8 |
3 files changed, 19 insertions, 4 deletions
diff --git a/filter/source/graphicfilter/icgm/class1.cxx b/filter/source/graphicfilter/icgm/class1.cxx index 2661931d7df2..30e28dd820cc 100644 --- a/filter/source/graphicfilter/icgm/class1.cxx +++ b/filter/source/graphicfilter/icgm/class1.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <o3tl/safeint.hxx> + #include "bundles.hxx" #include "cgm.hxx" #include "elements.hxx" @@ -169,7 +173,7 @@ void CGM::ImplDoClass1() { sal_uInt32 nSize = ImplGetUI(1); - if (static_cast<sal_uInt32>(mpEndValidSource - (mpSource + mnParaSize)) < nSize) + if (o3tl::make_unsigned(mpEndValidSource - (mpSource + mnParaSize)) < nSize) throw css::uno::Exception("attempt to read past end of input", nullptr); pElement->aFontList.InsertName( mpSource + mnParaSize, nSize ); diff --git a/filter/source/graphicfilter/icgm/class4.cxx b/filter/source/graphicfilter/icgm/class4.cxx index 4760215ebe18..2e3f3c439cdb 100644 --- a/filter/source/graphicfilter/icgm/class4.cxx +++ b/filter/source/graphicfilter/icgm/class4.cxx @@ -23,6 +23,9 @@ #include "chart.hxx" #include "elements.hxx" #include "outact.hxx" + +#include <o3tl/safeint.hxx> + #include <math.h> #include <memory> @@ -186,7 +189,7 @@ void CGM::ImplDoClass4() sal_uInt32 nType = ImplGetUI16(); sal_uInt32 nSize = ImplGetUI( 1 ); - if (static_cast<sal_uInt32>(mpEndValidSource - (mpSource + mnParaSize)) < nSize) + if (o3tl::make_unsigned(mpEndValidSource - (mpSource + mnParaSize)) < nSize) throw css::uno::Exception("attempt to read past end of input", nullptr); OUString aStr(reinterpret_cast<char*>(mpSource) + mnParaSize, nSize, RTL_TEXTENCODING_ASCII_US); @@ -223,7 +226,7 @@ void CGM::ImplDoClass4() sal_uInt32 nType = ImplGetUI16(); sal_uInt32 nSize = ImplGetUI(1); - if (static_cast<sal_uInt32>(mpEndValidSource - (mpSource + mnParaSize)) < nSize) + if (o3tl::make_unsigned(mpEndValidSource - (mpSource + mnParaSize)) < nSize) throw css::uno::Exception("attempt to read past end of input", nullptr); OUString aStr(reinterpret_cast<char*>(mpSource) + mnParaSize, nSize, RTL_TEXTENCODING_ASCII_US); @@ -240,7 +243,7 @@ void CGM::ImplDoClass4() (void)ImplGetUI16(); // nType sal_uInt32 nSize = ImplGetUI( 1 ); - if (static_cast<sal_uInt32>(mpEndValidSource - (mpSource + mnParaSize)) <= nSize) + if (o3tl::make_unsigned(mpEndValidSource - (mpSource + mnParaSize)) <= nSize) throw css::uno::Exception("attempt to read past end of input", nullptr); mpSource[ mnParaSize + nSize ] = 0; diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx index ae28ca4b6570..6d8d1304fdf3 100644 --- a/include/o3tl/safeint.hxx +++ b/include/o3tl/safeint.hxx @@ -12,6 +12,7 @@ #include <sal/config.h> +#include <cassert> #include <limits> #include <type_traits> @@ -226,6 +227,13 @@ template<typename T> inline typename std::enable_if<std::is_unsigned<T>::value, #endif +template<typename T> constexpr std::enable_if_t<std::is_signed_v<T>, std::make_unsigned_t<T>> +make_unsigned(T value) +{ + assert(value >= 0); + return value; +} + } #endif |