diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-04-04 17:05:46 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-04-05 00:24:53 +0200 |
commit | 40bc6c1380226677ef72b9667dba9d577087dfc6 (patch) | |
tree | 985a4b5d7ba4df1262d98a32d3590a0d8074fe13 /include/vcl/BitmapTools.hxx | |
parent | 1f28de7e26cb9b12d74b743333dab72e08f53bec (diff) |
ofz#7365 Integer overflow
Change-Id: If56db771976a82399dc49fd90845e6569cbd2e8e
Reviewed-on: https://gerrit.libreoffice.org/52400
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'include/vcl/BitmapTools.hxx')
-rw-r--r-- | include/vcl/BitmapTools.hxx | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/include/vcl/BitmapTools.hxx b/include/vcl/BitmapTools.hxx index 75c68e9ab67a..00f7d1b89b5e 100644 --- a/include/vcl/BitmapTools.hxx +++ b/include/vcl/BitmapTools.hxx @@ -22,6 +22,7 @@ #include <com/sun/star/geometry/IntegerRectangle2D.hpp> #include <basegfx/range/b2drectangle.hxx> #include <basegfx/matrix/b2dhommatrix.hxx> +#include <o3tl/safeint.hxx> namespace vcl { namespace bitmap { @@ -37,11 +38,17 @@ friend BitmapEx VCL_DLLPUBLIC CreateFromData( RawBitmap&& rawBitmap ); sal_uInt8 mnBitCount; public: RawBitmap(Size const & rSize, sal_uInt8 nBitCount) - : mpData(new sal_uInt8[ rSize.getWidth() * nBitCount/8 * rSize.getHeight()]), - maSize(rSize), + : maSize(rSize), mnBitCount(nBitCount) { assert(nBitCount == 24 || nBitCount == 32); + sal_Int32 nRowSize, nDataSize; + if (o3tl::checked_multiply<sal_Int32>(rSize.getWidth(), nBitCount/8, nRowSize) || + o3tl::checked_multiply<sal_Int32>(nRowSize, rSize.getHeight(), nDataSize)) + { + throw std::bad_alloc(); + } + mpData.reset(new sal_uInt8[nDataSize]); } void SetPixel(long nY, long nX, Color nColor) { |