vcl/source/gdi/svmconverter.cxx |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

New commits:
commit 13f95543670e1ad23b878a55a33942e88ef0b80f
Author:     Caolán McNamara <[email protected]>
AuthorDate: Fri Mar 4 10:38:50 2022 +0000
Commit:     Michael Stahl <[email protected]>
CommitDate: Fri Mar 11 15:44:47 2022 +0100

    clamp and add some logging like SvmReader
    
    LIBREOFFICE-OWMTGGWJ
    
    Change-Id: I8f744e1ab2684a0f0995abcc3e753a684a3b970a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130982
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <[email protected]>
    (cherry picked from commit 19add15932e579c931480eed42eeea52d0551897)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131369
    Tested-by: Michael Stahl <[email protected]>

diff --git a/vcl/source/gdi/svmconverter.cxx b/vcl/source/gdi/svmconverter.cxx
index dc48dea5c718..f61cbdb4e29c 100644
--- a/vcl/source/gdi/svmconverter.cxx
+++ b/vcl/source/gdi/svmconverter.cxx
@@ -244,6 +244,23 @@ namespace
             nFollowingActionCount = remainingActions;
         return std::min(remainingActions, nFollowingActionCount);
     }
+
+    void ClampRange(const OUString& rStr, sal_Int32& rIndex, sal_Int32& 
rLength)
+    {
+        const sal_Int32 nStrLength = rStr.getLength();
+
+        if (rIndex < 0 || rIndex > nStrLength)
+        {
+            SAL_WARN("vcl.gdi", "inconsistent offset");
+            rIndex = nStrLength;
+        }
+
+        if (rLength < 0 || rLength > nStrLength - rIndex)
+        {
+            SAL_WARN("vcl.gdi", "inconsistent len");
+            rLength = nStrLength - rIndex;
+        }
+    }
 }
 
 #define LF_FACESIZE 32
@@ -687,6 +704,7 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, 
GDIMetaFile& rMtf )
                     OUString aStr(OStringToOUString(aByteStr, eActualCharSet));
                     if ( nUnicodeCommentActionNumber == i )
                         ImplReadUnicodeComment( nUnicodeCommentStreamPos, 
rIStm, aStr );
+                    ClampRange(aStr, nIndex, nLen);
                     rMtf.AddAction( new MetaTextAction( aPt, aStr, nIndex, 
nLen ) );
                 }
 
@@ -777,6 +795,7 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, 
GDIMetaFile& rMtf )
                     }
                     if ( nUnicodeCommentActionNumber == i )
                         ImplReadUnicodeComment( nUnicodeCommentStreamPos, 
rIStm, aStr );
+                    ClampRange(aStr, nIndex, nLen);
                     rMtf.AddAction( new MetaTextArrayAction( aPt, aStr, 
pDXAry.get(), nIndex, nLen ) );
                 }
 
@@ -803,6 +822,7 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, 
GDIMetaFile& rMtf )
                     OUString aStr(OStringToOUString(aByteStr, eActualCharSet));
                     if ( nUnicodeCommentActionNumber == i )
                         ImplReadUnicodeComment( nUnicodeCommentStreamPos, 
rIStm, aStr );
+                    ClampRange(aStr, nIndex, nLen);
                     rMtf.AddAction( new MetaStretchTextAction( aPt, nWidth, 
aStr, nIndex, nLen ) );
                 }
 

Reply via email to