From d96b939fbfb140d605965f379b526786e7cc613e Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 16 Sep 2015 14:17:35 +0100 Subject: make CalcMaskShift a verifiable operation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and check it on untrusted data Change-Id: I7c97a27d70f91b9686adf9dcb8b68c5aa25c2b4c Reviewed-on: https://gerrit.libreoffice.org/18637 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- vcl/unx/generic/gdi/salbmp.cxx | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'vcl/unx') diff --git a/vcl/unx/generic/gdi/salbmp.cxx b/vcl/unx/generic/gdi/salbmp.cxx index c6c156b2c29b..82044492904f 100644 --- a/vcl/unx/generic/gdi/salbmp.cxx +++ b/vcl/unx/generic/gdi/salbmp.cxx @@ -154,14 +154,30 @@ BitmapBuffer* X11SalBitmap::ImplCreateDIB( case( 8 ): pDIB->mnFormat |= BMP_FORMAT_8BIT_PAL; break; #ifdef OSL_BIGENDIAN case(16 ): + { pDIB->mnFormat|= BMP_FORMAT_16BIT_TC_MSB_MASK; - pDIB->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f ); + ColorMaskElement aRedMask(0xf800); + aRedMask.CalcMaskShift(); + ColorMaskElement aGreenMask(0x07e0); + aGreenMask.CalcMaskShift(); + ColorMaskElement aBlueMask(0x001f); + aBlueMask.CalcMaskShift(); + pDIB->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); break; + } #else case(16 ): + { pDIB->mnFormat|= BMP_FORMAT_16BIT_TC_LSB_MASK; - pDIB->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f ); + ColorMaskElement aRedMask(0xf800); + aRedMask.CalcMaskShift(); + ColorMaskElement aGreenMask(0x07e0); + aGreenMask.CalcMaskShift(); + ColorMaskElement aBlueMask(0x001f); + aBlueMask.CalcMaskShift(); + pDIB->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); break; + } #endif default: nBitCount = 24; @@ -274,7 +290,13 @@ BitmapBuffer* X11SalBitmap::ImplCreateDIB( case( 16 ): { - aSrcBuf.maColorMask = ColorMask( pImage->red_mask, pImage->green_mask, pImage->blue_mask ); + ColorMaskElement aRedMask(pImage->red_mask); + aRedMask.CalcMaskShift(); + ColorMaskElement aGreenMask(pImage->green_mask); + aGreenMask.CalcMaskShift(); + ColorMaskElement aBlueMask(pImage->blue_mask); + aBlueMask.CalcMaskShift(); + aSrcBuf.maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); if( LSBFirst == pImage->byte_order ) { @@ -444,7 +466,13 @@ XImage* X11SalBitmap::ImplCreateXImage( #endif - xMask.reset(new ColorMask( pImage->red_mask, pImage->green_mask, pImage->blue_mask )); + ColorMaskElement aRedMask(pImage->red_mask); + aRedMask.CalcMaskShift(); + ColorMaskElement aGreenMask(pImage->green_mask); + aGreenMask.CalcMaskShift(); + ColorMaskElement aBlueMask(pImage->blue_mask); + aBlueMask.CalcMaskShift(); + xMask.reset(new ColorMask(aRedMask, aGreenMask, aBlueMask)); } break; -- cgit