vcl/source/filter/svm/SvmConverter.cxx |   22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

New commits:
commit b279061b97e53b0730bdd463b3287c82075f1538
Author:     zhutyra <zhutyra>
AuthorDate: Fri Mar 4 10:38:50 2022 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Fri Mar 4 13:36:21 2022 +0100

    clamp svm1 text ranges to legal range on conversion
    
    LIBREOFFICE-OWMTGGWJ
    
    Change-Id: Ief2770fd8dc48be9f1f102b709a1c3be0165b195
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130970
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/vcl/source/filter/svm/SvmConverter.cxx 
b/vcl/source/filter/svm/SvmConverter.cxx
index 30f3048f3792..189be4b7a398 100644
--- a/vcl/source/filter/svm/SvmConverter.cxx
+++ b/vcl/source/filter/svm/SvmConverter.cxx
@@ -248,6 +248,19 @@ namespace
             nFollowingActionCount = remainingActions;
         return std::min(remainingActions, nFollowingActionCount);
     }
+
+    bool NormalizeRange(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))
+        {
+            pDXAry->resize(rLength);
+        }
+        return rLength > 0;
+    }
 }
 
 #define LF_FACESIZE 32
@@ -691,7 +704,8 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, 
GDIMetaFile& rMtf )
                     OUString aStr(OStringToOUString(aByteStr, eActualCharSet));
                     if ( nUnicodeCommentActionNumber == i )
                         ImplReadUnicodeComment( nUnicodeCommentStreamPos, 
rIStm, aStr );
-                    rMtf.AddAction( new MetaTextAction( aPt, aStr, nIndex, 
nLen ) );
+                    if (NormalizeRange(aStr, nIndex, nLen))
+                        rMtf.AddAction( new MetaTextAction( aPt, aStr, nIndex, 
nLen ) );
                 }
 
                 if (nActionSize < 24)
@@ -780,7 +794,8 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, 
GDIMetaFile& rMtf )
                     }
                     if ( nUnicodeCommentActionNumber == i )
                         ImplReadUnicodeComment( nUnicodeCommentStreamPos, 
rIStm, aStr );
-                    rMtf.AddAction( new MetaTextArrayAction( aPt, aStr, 
aDXAry, nIndex, nLen ) );
+                    if (NormalizeRange(aStr, nIndex, nLen, &aDXAry))
+                        rMtf.AddAction( new MetaTextArrayAction( aPt, aStr, 
aDXAry, nIndex, nLen ) );
                 }
 
                 if (nActionSize < 24)
@@ -806,7 +821,8 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, 
GDIMetaFile& rMtf )
                     OUString aStr(OStringToOUString(aByteStr, eActualCharSet));
                     if ( nUnicodeCommentActionNumber == i )
                         ImplReadUnicodeComment( nUnicodeCommentStreamPos, 
rIStm, aStr );
-                    rMtf.AddAction( new MetaStretchTextAction( aPt, nWidth, 
aStr, nIndex, nLen ) );
+                    if (NormalizeRange(aStr, nIndex, nLen))
+                        rMtf.AddAction( new MetaStretchTextAction( aPt, 
nWidth, aStr, nIndex, nLen ) );
                 }
 
                 if (nActionSize < 28)

Reply via email to