include/svtools/svparser.hxx      |    1 +
 svtools/source/svrtf/svparser.cxx |   11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

New commits:
commit 1faac635fd37dd04f78c9b420ffefd289969c90d
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Sun Aug 6 20:55:32 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Mon Aug 7 11:24:23 2023 +0200

    ofz#57384 Timeout
    
    Change-Id: Ic2007f52056acd46f96d454c1fdb7b8ca8838d70
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155386
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/include/svtools/svparser.hxx b/include/svtools/svparser.hxx
index e1a74840add0..1b9431a69ee6 100644
--- a/include/svtools/svparser.hxx
+++ b/include/svtools/svparser.hxx
@@ -51,6 +51,7 @@ protected:
     OUStringBuffer      aToken;             // scanned token
     sal_uInt32          nlLineNr;           // current line number
     sal_uInt32          nlLinePos;          // current column number
+    sal_uInt32          nConversionErrors;  // count of conversion errors
 
     std::unique_ptr<SvParser_Impl<T>> pImplData; // internal data
     tools::Long                m_nTokenIndex;      // current token index to 
detect loops for seeking backwards
diff --git a/svtools/source/svrtf/svparser.cxx 
b/svtools/source/svrtf/svparser.cxx
index 1a8e73d0edb6..c003bcae21a9 100644
--- a/svtools/source/svrtf/svparser.cxx
+++ b/svtools/source/svrtf/svparser.cxx
@@ -78,6 +78,7 @@ SvParser<T>::SvParser( SvStream& rIn, sal_uInt8 nStackSize )
     : rInput( rIn )
     , nlLineNr( 1 )
     , nlLinePos( 1 )
+    , nConversionErrors( 0 )
     , pImplData( nullptr )
     , m_nTokenIndex(0)
     , nTokenValue( 0 )
@@ -338,6 +339,7 @@ sal_uInt32 SvParser<T>::GetNextChar()
                                     // do
                                     c = '?';
                                     nChars = 1;
+                                    ++nConversionErrors;
                                 }
                             }
                         }
@@ -384,6 +386,7 @@ sal_uInt32 SvParser<T>::GetNextChar()
                                     c = reinterpret_cast<unsigned char&>( 
sBuffer[0] );
                                     rInput.SeekRel( -(nLen-1) );
                                     nChars = 1;
+                                    ++nConversionErrors;
                                 }
                             }
                         }
@@ -405,7 +408,7 @@ sal_uInt32 SvParser<T>::GetNextChar()
                         // because a conversion is not available, do no 
conversion at all.
                         c = reinterpret_cast<unsigned char&>( c1 );
                         nChars = 1;
-
+                        ++nConversionErrors;
                     }
                 }
             }
@@ -416,6 +419,12 @@ sal_uInt32 SvParser<T>::GetNextChar()
     if ( ! rtl::isUnicodeScalarValue( c ) )
         c = '?' ;
 
+    if (bFuzzing && nConversionErrors > 128)
+    {
+        SAL_WARN("svtools", "SvParser::GetNextChar too many conversion errors 
while fuzzing, abandoning for performance");
+        bErr = true;
+    }
+
     if( bErr )
     {
         if( ERRCODE_IO_PENDING == rInput.GetError() )

Reply via email to