summaryrefslogtreecommitdiff
path: root/include/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2015-09-16 14:17:35 +0100
committerCaolán McNamara <caolanm@redhat.com>2015-09-17 08:51:27 +0000
commitd96b939fbfb140d605965f379b526786e7cc613e (patch)
tree4f59c852dc449c0bd0a9b218e671bc117e0721ae /include/vcl
parent57ad819ca658cb94c84ee30846d6781a5f931973 (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 'include/vcl')
-rw-r--r--include/vcl/salbtype.hxx47
1 files changed, 20 insertions, 27 deletions
diff --git a/include/vcl/salbtype.hxx b/include/vcl/salbtype.hxx
index eb3b6d30e6f8..82ae03646a11 100644
--- a/include/vcl/salbtype.hxx
+++ b/include/vcl/salbtype.hxx
@@ -187,29 +187,29 @@ struct VCL_DLLPUBLIC ColorMaskElement
int mnShift;
int mnOrShift;
sal_uInt8 mnOr;
- ColorMaskElement(sal_uInt32 nMask)
+ explicit ColorMaskElement(sal_uInt32 nMask = 0)
: mnMask(nMask)
, mnShift(0)
, mnOrShift(0)
, mnOr(0)
{
}
- static bool CalcMaskShift(ColorMaskElement &rElem)
+ bool CalcMaskShift()
{
- if (rElem.mnMask == 0)
+ if (mnMask == 0)
return true;
// from which bit starts the mask?
int nShift = 31;
- while( nShift >= 0 && !( rElem.mnMask & ( 1 << nShift ) ) )
+ while( nShift >= 0 && !( mnMask & ( 1 << nShift ) ) )
--nShift;
- rElem.mnShift = nShift - 7;
+ mnShift = nShift - 7;
int nLen = 0;
// XXX determine number of bits set => walk right until null
- while( nShift >= 0 && ( rElem.mnMask & ( 1 << nShift ) ) )
+ while( nShift >= 0 && ( mnMask & ( 1 << nShift ) ) )
{
nShift--;
nLen++;
@@ -218,8 +218,8 @@ struct VCL_DLLPUBLIC ColorMaskElement
if (nLen > 8) // mask length must be 8 bits or less
return false;
- rElem.mnOrShift = 8 - nLen;
- rElem.mnOr = static_cast<sal_uInt8>( ( 0xFF >> nLen ) << rElem.mnOrShift );
+ mnOrShift = 8 - nLen;
+ mnOr = static_cast<sal_uInt8>( ( 0xFF >> nLen ) << mnOrShift );
return true;
}
@@ -235,11 +235,18 @@ class VCL_DLLPUBLIC ColorMask
public:
- inline ColorMask( sal_uInt32 nRedMask = 0,
- sal_uInt32 nGreenMask = 0,
- sal_uInt32 nBlueMask = 0,
- sal_uInt32 nAlphaChannel = 0 );
- inline ~ColorMask() {}
+ ColorMask(const ColorMaskElement& rRedMask = ColorMaskElement(),
+ const ColorMaskElement& rGreenMask = ColorMaskElement(),
+ const ColorMaskElement& rBlueMask = ColorMaskElement(),
+ sal_uInt32 nAlphaChannel = 0)
+ : maR(rRedMask)
+ , maG(rGreenMask)
+ , maB(rBlueMask)
+ , mnAlphaChannel(nAlphaChannel)
+ {
+ }
+
+ ~ColorMask() {}
inline sal_uInt32 GetRedMask() const;
inline sal_uInt32 GetGreenMask() const;
@@ -599,20 +606,6 @@ inline sal_uInt16 BitmapPalette::GetBestIndex( const BitmapColor& rCol ) const
return nRetIndex;
}
-inline ColorMask::ColorMask( sal_uInt32 nRedMask,
- sal_uInt32 nGreenMask,
- sal_uInt32 nBlueMask,
- sal_uInt32 nAlphaChannel )
- : maR(nRedMask)
- , maG(nGreenMask)
- , maB(nBlueMask)
- , mnAlphaChannel(nAlphaChannel)
-{
- ColorMaskElement::CalcMaskShift(maR);
- ColorMaskElement::CalcMaskShift(maG);
- ColorMaskElement::CalcMaskShift(maB);
-}
-
inline sal_uInt32 ColorMask::GetRedMask() const
{
return maR.mnMask;