[Libreoffice-commits] core.git: include/svtools svtools/source
Caolán McNamara
caolanm at redhat.com
Tue Mar 27 14:52:22 UTC 2018
include/svtools/svparser.hxx | 1 +
svtools/source/svrtf/parrtf.cxx | 8 +++++++-
svtools/source/svrtf/svparser.cxx | 5 +++++
3 files changed, 13 insertions(+), 1 deletion(-)
New commits:
commit f98040a273b14e8e3f4b7206d4e6c8b93dde262f
Author: Caolán McNamara <caolanm at redhat.com>
Date: Tue Mar 27 12:17:14 2018 +0100
another stab at the ofx infinite rtf loop
Change-Id: I2dcc186fd7118a85e2059d061fc4cac555c96ee8
Reviewed-on: https://gerrit.libreoffice.org/51944
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/include/svtools/svparser.hxx b/include/svtools/svparser.hxx
index 53564c727cdd..bb046d8083f4 100644
--- a/include/svtools/svparser.hxx
+++ b/include/svtools/svparser.hxx
@@ -54,6 +54,7 @@ protected:
sal_uLong nlLinePos; // current column number
std::unique_ptr<SvParser_Impl<T>> pImplData; // internal data
+ long m_nTokenIndex; // current token index to detect loops for seeking backwards
long nTokenValue; // additional value (RTF)
bool bTokenHasValue; // indicates whether nTokenValue is valid
SvParserState eState; // status also in derived classes
diff --git a/svtools/source/svrtf/parrtf.cxx b/svtools/source/svrtf/parrtf.cxx
index b6b4ffca6ddf..91a53b4381c6 100644
--- a/svtools/source/svrtf/parrtf.cxx
+++ b/svtools/source/svrtf/parrtf.cxx
@@ -602,8 +602,13 @@ void SvRTFParser::Continue( int nToken )
if( !nToken )
nToken = GetNextToken();
- while( IsParserWorking() )
+ bool bLooping = false;
+
+ while (IsParserWorking() && !bLooping)
{
+ auto nCurrentTokenIndex = m_nTokenIndex;
+ auto nCurrentToken = nToken;
+
SaveState( nToken );
switch( nToken )
{
@@ -660,6 +665,7 @@ NEXTTOKEN:
SaveState( 0 ); // processed till here,
// continue with new token!
nToken = GetNextToken();
+ bLooping = nCurrentTokenIndex == m_nTokenIndex && nToken == nCurrentToken;
}
if( SvParserState::Accepted == eState && 0 < nOpenBrakets )
eState = SvParserState::Error;
diff --git a/svtools/source/svrtf/svparser.cxx b/svtools/source/svrtf/svparser.cxx
index 27e6c1eede3d..4ba540ce96d9 100644
--- a/svtools/source/svrtf/svparser.cxx
+++ b/svtools/source/svrtf/svparser.cxx
@@ -76,6 +76,7 @@ SvParser<T>::SvParser( SvStream& rIn, sal_uInt8 nStackSize )
, nlLineNr( 1 )
, nlLinePos( 1 )
, pImplData( nullptr )
+ , m_nTokenIndex(0)
, nTokenValue( 0 )
, bTokenHasValue( false )
, eState( SvParserState::NotStarted )
@@ -475,6 +476,7 @@ T SvParser<T>::GetNextToken()
bTokenHasValue = pTokenStackPos->bTokenHasValue;
aToken = pTokenStackPos->sToken;
nRet = pTokenStackPos->nTokenId;
+ ++m_nTokenIndex;
}
// no, now push actual value on stack
else if( SvParserState::Working == eState )
@@ -483,6 +485,7 @@ T SvParser<T>::GetNextToken()
pTokenStackPos->nTokenValue = nTokenValue;
pTokenStackPos->bTokenHasValue = bTokenHasValue;
pTokenStackPos->nTokenId = nRet;
+ ++m_nTokenIndex;
}
else if( SvParserState::Accepted != eState && SvParserState::Pending != eState )
eState = SvParserState::Error; // an error occurred
@@ -501,6 +504,8 @@ T SvParser<T>::SkipToken( short nCnt ) // "skip" n Tokens backward
nTmp = nTokenStackSize;
nTokenStackPos = sal_uInt8(nTmp);
+ m_nTokenIndex -= nTmp;
+
// restore values
aToken = pTokenStackPos->sToken;
nTokenValue = pTokenStackPos->nTokenValue;
More information about the Libreoffice-commits
mailing list