diff options
-rw-r--r-- | emfio/source/reader/emfreader.cxx | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/emfio/source/reader/emfreader.cxx b/emfio/source/reader/emfreader.cxx index 51a8a6fb029b..6a974085d887 100644 --- a/emfio/source/reader/emfreader.cxx +++ b/emfio/source/reader/emfreader.cxx @@ -1360,14 +1360,16 @@ namespace emfio if(!aBitmapEx.IsEmpty()) { // test if it is sensible to crop - if ( ( cxSrc > 0 ) && ( cySrc > 0 ) && - ( xSrc >= 0 ) && ( ySrc >= 0 ) && - ( xSrc + cxSrc < aBitmapEx.GetSizePixel().Width() ) && - ( ySrc + cySrc < aBitmapEx.GetSizePixel().Height() ) ) + if (cxSrc > 0 && cySrc > 0 && xSrc >= 0 && ySrc >= 0) { - const tools::Rectangle aCropRect( Point( xSrc, ySrc ), Size( cxSrc, cySrc ) ); - - aBitmapEx.Crop( aCropRect ); + sal_Int32 xEndSrc; + sal_Int32 yEndSrc; + if (!o3tl::checked_add(xSrc, cxSrc, xEndSrc) && xEndSrc < aBitmapEx.GetSizePixel().Width() && + !o3tl::checked_add(ySrc, cySrc, yEndSrc) && yEndSrc < aBitmapEx.GetSizePixel().Height()) + { + const tools::Rectangle aCropRect( Point( xSrc, ySrc ), Size( cxSrc, cySrc ) ); + aBitmapEx.Crop( aCropRect ); + } } #ifdef DBG_UTIL |