diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-09-16 14:17:35 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-09-17 08:51:27 +0000 |
commit | d96b939fbfb140d605965f379b526786e7cc613e (patch) | |
tree | 4f59c852dc449c0bd0a9b218e671bc117e0721ae /vcl/opengl | |
parent | 57ad819ca658cb94c84ee30846d6781a5f931973 (diff) |
make CalcMaskShift a verifiable operation
and check it on untrusted data
Change-Id: I7c97a27d70f91b9686adf9dcb8b68c5aa25c2b4c
Reviewed-on: https://gerrit.libreoffice.org/18637
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 'vcl/opengl')
-rw-r--r-- | vcl/opengl/salbmp.cxx | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx index 286c4632837a..6144d9a04b2e 100644 --- a/vcl/opengl/salbmp.cxx +++ b/vcl/opengl/salbmp.cxx @@ -709,18 +709,44 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( BitmapAccessMode nMode ) pBuffer->mnScanlineSize = mnBytesPerRow; pBuffer->mpBits = maUserBuffer.get(); pBuffer->mnBitCount = mnBits; - switch( mnBits ) + switch (mnBits) { - case 1: pBuffer->mnFormat = BMP_FORMAT_1BIT_MSB_PAL; break; - case 4: pBuffer->mnFormat = BMP_FORMAT_4BIT_MSN_PAL; break; - case 8: pBuffer->mnFormat = BMP_FORMAT_8BIT_PAL; break; - case 16: pBuffer->mnFormat = BMP_FORMAT_16BIT_TC_MSB_MASK; - pBuffer->maColorMask = ColorMask( 0xf800, 0x07e0, 0x001f ); - break; - case 24: pBuffer->mnFormat = BMP_FORMAT_24BIT_TC_RGB; break; - case 32: pBuffer->mnFormat = BMP_FORMAT_32BIT_TC_RGBA; - pBuffer->maColorMask = ColorMask( 0xff000000, 0x00ff0000, 0x0000ff00 ); - break; + case 1: + pBuffer->mnFormat = BMP_FORMAT_1BIT_MSB_PAL; + break; + case 4: + pBuffer->mnFormat = BMP_FORMAT_4BIT_MSN_PAL; + break; + case 8: + pBuffer->mnFormat = BMP_FORMAT_8BIT_PAL; + break; + case 16: + { + pBuffer->mnFormat = BMP_FORMAT_16BIT_TC_MSB_MASK; + ColorMaskElement aRedMask(0xf800); + aRedMask.CalcMaskShift(); + ColorMaskElement aGreenMask(0x07e0); + aGreenMask.CalcMaskShift(); + ColorMaskElement aBlueMask(0x001f); + aBlueMask.CalcMaskShift(); + pBuffer->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); + break; + } + case 24: + pBuffer->mnFormat = BMP_FORMAT_24BIT_TC_RGB; + break; + case 32: + { + pBuffer->mnFormat = BMP_FORMAT_32BIT_TC_RGBA; + ColorMaskElement aRedMask(0xff000000); + aRedMask.CalcMaskShift(); + ColorMaskElement aGreenMask(0x00ff0000); + aGreenMask.CalcMaskShift(); + ColorMaskElement aBlueMask(0x0000ff00); + aBlueMask.CalcMaskShift(); + pBuffer->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); + break; + } } return pBuffer; |