Skip to content

Commit

Permalink
ofz#1605 check multiply and shift
Browse files Browse the repository at this point in the history
Change-Id: I6aad9ad23e7bf080b3b610223f92df7074530beb
Reviewed-on: https://gerrit.libreoffice.org/37632
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
  • Loading branch information
Caolán McNamara committed Jun 1, 2017
1 parent 259c240 commit 237d457
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
18 changes: 16 additions & 2 deletions vcl/headless/svpbmp.cxx
Expand Up @@ -27,7 +27,7 @@

#include <basegfx/vector/b2ivector.hxx>
#include <basegfx/range/b2ibox.hxx>

#include <o3tl/safeint.hxx>
#include <vcl/salbtype.hxx>
#include <vcl/bitmap.hxx>

Expand Down Expand Up @@ -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<long>(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 )
Expand Down
19 changes: 18 additions & 1 deletion vcl/source/gdi/salmisc.cxx
Expand Up @@ -20,6 +20,7 @@
#include <vcl/bitmapaccess.hxx>
#include <vcl/salbtype.hxx>
#include <bmpfast.hxx>
#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <memory>

Expand Down Expand Up @@ -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<long>(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 ];
Expand Down
17 changes: 16 additions & 1 deletion vcl/unx/generic/gdi/salbmp.cxx
Expand Up @@ -41,6 +41,7 @@
#include <unx/salinst.h>
#include <unx/x11/xlimits.hxx>

#include <o3tl/safeint.hxx>
#include <opengl/salbmp.hxx>
#include <vcl/opengl/OpenGLHelper.hxx>

Expand Down Expand Up @@ -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<long>(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 )
Expand Down

0 comments on commit 237d457

Please sign in to comment.