summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2015-08-25 11:58:42 +0200
committerCaolán McNamara <caolanm@redhat.com>2015-08-25 15:07:36 +0000
commit4c8bba9a8e7488b268fc4f6c9e06195b42565375 (patch)
tree2b1a0563c3301fa3117597b5a24f7d8346e7b0f2 /filter
parentdb39370e91c68910daf1f5959f6494b4891e7ba2 (diff)
Avoid overflow in PBMReader::ImplReadHeader
...as found by UBSan in CppunitTest_filter_ppm_test on filter/qa/cppunit/data/pbm/fail/crash-1.pbm Change-Id: Ib7c50ef1f07aba6b78f79c608be69c3dac38ddfe (cherry picked from commit 662498ab80833a2b671c247fb859603632e52105) Reviewed-on: https://gerrit.libreoffice.org/17984 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'filter')
-rw-r--r--filter/source/graphicfilter/ipbm/ipbm.cxx24
1 files changed, 24 insertions, 0 deletions
diff --git a/filter/source/graphicfilter/ipbm/ipbm.cxx b/filter/source/graphicfilter/ipbm/ipbm.cxx
index 18b32498eece..d7cf94145333 100644
--- a/filter/source/graphicfilter/ipbm/ipbm.cxx
+++ b/filter/source/graphicfilter/ipbm/ipbm.cxx
@@ -218,17 +218,41 @@ bool PBMReader::ImplReadHeader()
nDat -= '0';
if ( nCount == 0 )
{
+ if (mnWidth > SAL_MAX_INT32 / 10)
+ {
+ return false;
+ }
mnWidth *= 10;
+ if (nDat > SAL_MAX_INT32 - mnWidth)
+ {
+ return false;
+ }
mnWidth += nDat;
}
else if ( nCount == 1 )
{
+ if (mnHeight > SAL_MAX_INT32 / 10)
+ {
+ return false;
+ }
mnHeight *= 10;
+ if (nDat > SAL_MAX_INT32 - mnHeight)
+ {
+ return false;
+ }
mnHeight += nDat;
}
else if ( nCount == 2 )
{
+ if (mnMaxVal > std::numeric_limits<sal_uLong>::max() / 10)
+ {
+ return false;
+ }
mnMaxVal *= 10;
+ if (nDat > std::numeric_limits<sal_uLong>::max() - mnMaxVal)
+ {
+ return false;
+ }
mnMaxVal += nDat;
}
}