[Libreoffice-commits] core.git: sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Sun Sep 30 14:36:48 UTC 2018
sc/source/filter/dif/difimp.cxx | 41 ++++++++++++++++++++--------------------
sc/source/filter/inc/dif.hxx | 2 -
2 files changed, 22 insertions(+), 21 deletions(-)
New commits:
commit 20c6cff919e09bf3a42fa9e26cc3e7568743047d
Author: Caolán McNamara <caolanm at redhat.com>
AuthorDate: Sun Sep 30 13:49:24 2018 +0100
Commit: Caolán McNamara <caolanm at redhat.com>
CommitDate: Sun Sep 30 16:36:26 2018 +0200
ofz#10406 fuzzing oom
reduce repeated allocations totalling 2.944G worth of allocations to 877.4M,
peak usage remains unchanged at 4.2M
Change-Id: I9840bdb25a72021f6085fa318b51a687d5f36149
Reviewed-on: https://gerrit.libreoffice.org/61155
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/sc/source/filter/dif/difimp.cxx b/sc/source/filter/dif/difimp.cxx
index a17ef86c728b..8f759b0ba076 100644
--- a/sc/source/filter/dif/difimp.cxx
+++ b/sc/source/filter/dif/difimp.cxx
@@ -59,7 +59,7 @@ ErrCode ScFormatFilterPluginImpl::ScImportDif(SvStream& rIn, ScDocument* pDoc, c
bool bSyntErrWarn = false;
bool bOverflowWarn = false;
- OUString& aData = aDifParser.aData;
+ OUStringBuffer& rData = aDifParser.m_aData;
rIn.Seek( 0 );
@@ -71,7 +71,7 @@ ErrCode ScFormatFilterPluginImpl::ScImportDif(SvStream& rIn, ScDocument* pDoc, c
aPrgrsBar.Progress();
- const bool bData = !aData.isEmpty();
+ const bool bData = !rData.isEmpty();
switch( eTopic )
{
@@ -80,7 +80,7 @@ ErrCode ScFormatFilterPluginImpl::ScImportDif(SvStream& rIn, ScDocument* pDoc, c
if( aDifParser.nVector != 0 || aDifParser.nVal != 1 )
bSyntErrWarn = true;
if( bData )
- pDoc->RenameTab( nBaseTab, aData);
+ pDoc->RenameTab(nBaseTab, rData.toString());
}
break;
case T_VECTORS:
@@ -139,6 +139,8 @@ ErrCode ScFormatFilterPluginImpl::ScImportDif(SvStream& rIn, ScDocument* pDoc, c
aPrgrsBar.Progress();
ScAddress aPos(nColCnt, nRowCnt, nBaseTab);
+ OUString aData = rData.toString();
+
switch( eCurrent )
{
case D_BOT:
@@ -359,9 +361,9 @@ TOPIC DifParser::GetNextTopic()
OSL_ENSURE( aLine.getLength() >= 2,
"+GetNextTopic(): <String> is too short!" );
if( aLine.getLength() > 2 )
- aData = aLine.copy( 1, aLine.getLength() - 2 );
+ m_aData.append(aLine.copy(1, aLine.getLength() - 2));
else
- aData.clear();
+ m_aData.truncate();
eS = S_END;
break;
case S_END:
@@ -384,14 +386,14 @@ TOPIC DifParser::GetNextTopic()
return eRet;
}
-static void lcl_DeEscapeQuotesDif( OUString& rString )
+static void lcl_DeEscapeQuotesDif(OUStringBuffer& rString)
{
// Special handling for DIF import: Escaped (duplicated) quotes are resolved.
// Single quote characters are left in place because older versions didn't
// escape quotes in strings (and Excel doesn't when using the clipboard).
// The quotes around the string are removed before this function is called.
- rString = rString.replaceAll("\"\"", "\"");
+ rString = rString.toString().replaceAll("\"\"", "\"");
}
// Determine if passed in string is numeric data and set fVal/nNumFormat if so
@@ -494,7 +496,7 @@ DATASET DifParser::GetNextDataset()
}
break;
case '0': // Numeric Data
- pCurrentBuffer++; // value in fVal, 2. line in aData
+ pCurrentBuffer++; // value in fVal, 2. line in m_aData
if( *pCurrentBuffer == ',' )
{
pCurrentBuffer++;
@@ -503,15 +505,14 @@ DATASET DifParser::GetNextDataset()
ReadNextLine( aTmpLine );
if ( eRet == D_SYNT_ERROR )
{ // for broken records write "#ERR: data" to cell
- OUStringBuffer aTmp("#ERR: ");
- aTmp.append(pCurrentBuffer).append(" (");
- aTmp.append(aTmpLine).append(')');
- aData = aTmp.makeStringAndClear();
+ m_aData = "#ERR: ";
+ m_aData.append(pCurrentBuffer).append(" (");
+ m_aData.append(aTmpLine).append(')');
eRet = D_STRING;
}
else
{
- aData = aTmpLine;
+ m_aData = aTmpLine;
}
}
break;
@@ -532,19 +533,19 @@ DATASET DifParser::GetNextDataset()
// Single line string
if( nLineLength >= 2 && pLine[nLineLength - 1] == '"' )
{
- aData = aLine.copy( 1, nLineLength - 2 );
- lcl_DeEscapeQuotesDif( aData );
+ m_aData = aLine.copy( 1, nLineLength - 2 );
+ lcl_DeEscapeQuotesDif(m_aData);
eRet = D_STRING;
}
}
else
{
// Multiline string
- aData = aLine.copy( 1 );
+ m_aData = aLine.copy( 1 );
bool bContinue = true;
while ( bContinue )
{
- aData = aData + "\n";
+ m_aData.append("\n");
bContinue = !rIn.eof() && ReadNextLine( aLine );
if( bContinue )
{
@@ -555,12 +556,12 @@ DATASET DifParser::GetNextDataset()
bContinue = !LookAhead();
if( bContinue )
{
- aData = aData + aLine;
+ m_aData.append(aLine);
}
else if( pLine[nLineLength - 1] == '"' )
{
- aData = aData + aLine.copy(0, nLineLength -1 );
- lcl_DeEscapeQuotesDif( aData );
+ m_aData.append(aLine.copy(0, nLineLength -1));
+ lcl_DeEscapeQuotesDif(m_aData);
eRet = D_STRING;
}
}
diff --git a/sc/source/filter/inc/dif.hxx b/sc/source/filter/inc/dif.hxx
index 5d29bbd8aef1..d01e281a46f7 100644
--- a/sc/source/filter/inc/dif.hxx
+++ b/sc/source/filter/inc/dif.hxx
@@ -58,7 +58,7 @@ enum DATASET { D_BOT, D_EOD, D_NUMERIC, D_STRING, D_UNKNOWN, D_SYNT_ERROR };
class DifParser
{
public:
- OUString aData;
+ OUStringBuffer m_aData;
double fVal;
sal_uInt32 nVector;
sal_uInt32 nVal;
More information about the Libreoffice-commits
mailing list