diff --git a/vcl/headless/svpbmp.cxx b/vcl/headless/svpbmp.cxx index 3091dfba888ce..5be976fc9e748 100644 --- a/vcl/headless/svpbmp.cxx +++ b/vcl/headless/svpbmp.cxx @@ -27,7 +27,7 @@ #include #include - +#include #include #include @@ -112,7 +112,21 @@ BitmapBuffer* ImplCreateDIB( pDIB->mnFormat |= ScanlineFormat::TopDown; pDIB->mnWidth = rSize.Width(); pDIB->mnHeight = rSize.Height(); - pDIB->mnScanlineSize = AlignedWidth4Bytes( pDIB->mnWidth * nBitCount ); + long nScanlineBase; + bool bFail = o3tl::checked_multiply(pDIB->mnWidth, nBitCount, nScanlineBase); + if (bFail) + { + SAL_WARN("vcl.gdi", "checked multiply failed"); + delete pDIB; + return nullptr; + } + pDIB->mnScanlineSize = AlignedWidth4Bytes(nScanlineBase); + if (pDIB->mnScanlineSize < nScanlineBase/8) + { + SAL_WARN("vcl.gdi", "scanline calculation wraparound"); + delete pDIB; + return nullptr; + } pDIB->mnBitCount = nBitCount; if( nColors ) diff --git a/vcl/source/gdi/salmisc.cxx b/vcl/source/gdi/salmisc.cxx index ffde759517fa6..4f239efb95c6e 100644 --- a/vcl/source/gdi/salmisc.cxx +++ b/vcl/source/gdi/salmisc.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -328,7 +329,23 @@ BitmapBuffer* StretchAndConvert( pDstBuffer->mnFormat = nDstBitmapFormat; pDstBuffer->mnWidth = rTwoRect.mnDestWidth; pDstBuffer->mnHeight = rTwoRect.mnDestHeight; - pDstBuffer->mnScanlineSize = AlignedWidth4Bytes( pDstBuffer->mnBitCount * pDstBuffer->mnWidth ); + long nScanlineBase; + bool bFail = o3tl::checked_multiply(pDstBuffer->mnBitCount, pDstBuffer->mnWidth, nScanlineBase); + if (bFail) + { + SAL_WARN("vcl.gdi", "checked multiply failed"); + pDstBuffer->mpBits = nullptr; + delete pDstBuffer; + return nullptr; + } + pDstBuffer->mnScanlineSize = AlignedWidth4Bytes(nScanlineBase); + if (pDstBuffer->mnScanlineSize < nScanlineBase/8) + { + SAL_WARN("vcl.gdi", "scanline calculation wraparound"); + pDstBuffer->mpBits = nullptr; + delete pDstBuffer; + return nullptr; + } try { pDstBuffer->mpBits = new sal_uInt8[ pDstBuffer->mnScanlineSize * pDstBuffer->mnHeight ]; diff --git a/vcl/unx/generic/gdi/salbmp.cxx b/vcl/unx/generic/gdi/salbmp.cxx index 73fc5a4241522..00043d5e783e8 100644 --- a/vcl/unx/generic/gdi/salbmp.cxx +++ b/vcl/unx/generic/gdi/salbmp.cxx @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -193,7 +194,21 @@ BitmapBuffer* X11SalBitmap::ImplCreateDIB( pDIB->mnWidth = rSize.Width(); pDIB->mnHeight = rSize.Height(); - pDIB->mnScanlineSize = AlignedWidth4Bytes( pDIB->mnWidth * nBitCount ); + long nScanlineBase; + bool bFail = o3tl::checked_multiply(pDIB->mnWidth, nBitCount, nScanlineBase); + if (bFail) + { + SAL_WARN("vcl.gdi", "checked multiply failed"); + delete pDIB; + return nullptr; + } + pDIB->mnScanlineSize = AlignedWidth4Bytes(nScanlineBase); + if (pDIB->mnScanlineSize < nScanlineBase/8) + { + SAL_WARN("vcl.gdi", "scanline calculation wraparound"); + delete pDIB; + return nullptr; + } pDIB->mnBitCount = nBitCount; if( nColors )