summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-03-04 11:07:49 +0000
committerCaolán McNamara <caolanm@redhat.com>2022-03-04 16:41:30 +0100
commit4015c18130ced8dcfdfaec99b11cd914beec0449 (patch)
tree20889f6d557f1f97d690ad436bf12b65cedbd08b /vcl
parent626e05a221909bcb068b5ef6af8be9356ce6d640 (diff)
clamp and add some logging like SvmReader
Change-Id: I8f744e1ab2684a0f0995abcc3e753a684a3b970a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130971 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/filter/svm/SvmConverter.cxx34
1 files changed, 21 insertions, 13 deletions
diff --git a/vcl/source/filter/svm/SvmConverter.cxx b/vcl/source/filter/svm/SvmConverter.cxx
index 189be4b7a398..004abcd4d751 100644
--- a/vcl/source/filter/svm/SvmConverter.cxx
+++ b/vcl/source/filter/svm/SvmConverter.cxx
@@ -249,17 +249,25 @@ namespace
return std::min(remainingActions, nFollowingActionCount);
}
- bool NormalizeRange(const OUString& rStr, sal_Int32& rIndex, sal_Int32& rLength,
+ void ClampRange(const OUString& rStr, sal_Int32& rIndex, sal_Int32& rLength,
std::vector<sal_Int32>* pDXAry = nullptr)
{
- const sal_uInt32 nStrLength = rStr.getLength();
- rIndex = std::min<sal_uInt32>(rIndex, nStrLength);
- rLength = std::min<sal_uInt32>(rLength, nStrLength - rIndex);
- if (pDXAry && pDXAry->size() > o3tl::make_unsigned(rLength))
+ const sal_Int32 nStrLength = rStr.getLength();
+
+ if (rIndex < 0 || rIndex > nStrLength)
{
- pDXAry->resize(rLength);
+ SAL_WARN("vcl.gdi", "inconsistent offset");
+ rIndex = nStrLength;
}
- return rLength > 0;
+
+ if (rLength < 0 || rLength > nStrLength - rIndex)
+ {
+ SAL_WARN("vcl.gdi", "inconsistent len");
+ rLength = nStrLength - rIndex;
+ }
+
+ if (pDXAry && pDXAry->size() > o3tl::make_unsigned(rLength))
+ pDXAry->resize(rLength);
}
}
@@ -704,8 +712,8 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf )
OUString aStr(OStringToOUString(aByteStr, eActualCharSet));
if ( nUnicodeCommentActionNumber == i )
ImplReadUnicodeComment( nUnicodeCommentStreamPos, rIStm, aStr );
- if (NormalizeRange(aStr, nIndex, nLen))
- rMtf.AddAction( new MetaTextAction( aPt, aStr, nIndex, nLen ) );
+ ClampRange(aStr, nIndex, nLen);
+ rMtf.AddAction( new MetaTextAction( aPt, aStr, nIndex, nLen ) );
}
if (nActionSize < 24)
@@ -794,8 +802,8 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf )
}
if ( nUnicodeCommentActionNumber == i )
ImplReadUnicodeComment( nUnicodeCommentStreamPos, rIStm, aStr );
- if (NormalizeRange(aStr, nIndex, nLen, &aDXAry))
- rMtf.AddAction( new MetaTextArrayAction( aPt, aStr, aDXAry, nIndex, nLen ) );
+ ClampRange(aStr, nIndex, nLen, &aDXAry);
+ rMtf.AddAction( new MetaTextArrayAction( aPt, aStr, aDXAry, nIndex, nLen ) );
}
if (nActionSize < 24)
@@ -821,8 +829,8 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf )
OUString aStr(OStringToOUString(aByteStr, eActualCharSet));
if ( nUnicodeCommentActionNumber == i )
ImplReadUnicodeComment( nUnicodeCommentStreamPos, rIStm, aStr );
- if (NormalizeRange(aStr, nIndex, nLen))
- rMtf.AddAction( new MetaStretchTextAction( aPt, nWidth, aStr, nIndex, nLen ) );
+ ClampRange(aStr, nIndex, nLen);
+ rMtf.AddAction( new MetaStretchTextAction( aPt, nWidth, aStr, nIndex, nLen ) );
}
if (nActionSize < 28)