[Libreoffice-commits] core.git: sw/qa sw/source
Michael Stahl (via logerrit)
logerrit at kemper.freedesktop.org
Fri Nov 15 08:54:43 UTC 2019
sw/qa/core/data/ww5/pass/ofz18526-1.doc |binary
sw/source/filter/ww8/ww8par.cxx | 54 ++++++++++++++++++++++++--------
sw/source/filter/ww8/ww8par.hxx | 2 +
sw/source/filter/ww8/ww8par5.cxx | 5 +-
4 files changed, 47 insertions(+), 14 deletions(-)
New commits:
commit 7ecda38cdaa2361e8510bf3e7206863c4936deab
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Nov 12 18:57:58 2019 +0100
Commit: Caolán McNamara <caolanm at redhat.com>
CommitDate: Fri Nov 15 09:53:10 2019 +0100
ofz#18526 sw: WW8 import: don't insert control characters
Sanitize string before calling InsertString().
This segfaults since:
commit b522fc0646915d4da94df38dd249c88b28f25be7
Date: Tue Sep 24 18:11:45 2019 +0200
sw: maintain fieldmarks in DeleteRange()/DeleteAndJoin()/ReplaceRange()
Change-Id: I9ef73d924420686f6838fa21900ec57b4d25c905
Reviewed-on: https://gerrit.libreoffice.org/81949
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/sw/qa/core/data/ww5/pass/ofz18526-1.doc b/sw/qa/core/data/ww5/pass/ofz18526-1.doc
new file mode 100644
index 000000000000..e651650f9a26
Binary files /dev/null and b/sw/qa/core/data/ww5/pass/ofz18526-1.doc differ
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 445744b2912a..2a9f285b5757 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -123,6 +123,8 @@
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/document/XViewDataSupplier.hpp>
#include <com/sun/star/document/IndexedPropertyValues.hpp>
+
+#include <svl/lngmisc.hxx>
#include <svl/itemiter.hxx>
#include <comphelper/processfactory.hxx>
@@ -3408,13 +3410,37 @@ void SwWW8ImplReader::emulateMSWordAddTextToParagraph(const OUString& rAddString
}
}
+namespace sw {
+
+auto FilterControlChars(OUString const& rString) -> OUString
+{
+ OUStringBuffer buf(rString.getLength());
+ for (sal_Int32 i = 0; i < rString.getLength(); ++i)
+ {
+ sal_Unicode const ch(rString[i]);
+ if (!linguistic::IsControlChar(ch) || ch == '\r' || ch == '\n' || ch == '\t')
+ {
+ buf.append(ch);
+ }
+ else
+ {
+ SAL_INFO("sw.ww8", "filtering control character");
+ }
+ }
+ return buf.makeStringAndClear();
+}
+
+} // namespace sw
+
void SwWW8ImplReader::simpleAddTextToParagraph(const OUString& rAddString)
{
- if (rAddString.isEmpty())
+ OUString const addString(sw::FilterControlChars(rAddString));
+
+ if (addString.isEmpty())
return;
#if OSL_DEBUG_LEVEL > 1
- SAL_INFO("sw.ww8", "<addTextToParagraph>" << rAddString << "</addTextToParagraph>");
+ SAL_INFO("sw.ww8", "<addTextToParagraph>" << addString << "</addTextToParagraph>");
#endif
const SwContentNode *pCntNd = m_pPaM->GetContentNode();
@@ -3428,21 +3454,21 @@ void SwWW8ImplReader::simpleAddTextToParagraph(const OUString& rAddString)
const sal_Int32 nCharsLeft = SAL_MAX_INT32 - pNd->GetText().getLength();
if (nCharsLeft > 0)
{
- if (rAddString.getLength() <= nCharsLeft)
+ if (addString.getLength() <= nCharsLeft)
{
- m_rDoc.getIDocumentContentOperations().InsertString(*m_pPaM, rAddString);
+ m_rDoc.getIDocumentContentOperations().InsertString(*m_pPaM, addString);
}
else
{
- m_rDoc.getIDocumentContentOperations().InsertString(*m_pPaM, rAddString.copy(0, nCharsLeft));
+ m_rDoc.getIDocumentContentOperations().InsertString(*m_pPaM, addString.copy(0, nCharsLeft));
AppendTextNode(*m_pPaM->GetPoint());
- m_rDoc.getIDocumentContentOperations().InsertString(*m_pPaM, rAddString.copy(nCharsLeft));
+ m_rDoc.getIDocumentContentOperations().InsertString(*m_pPaM, addString.copy(nCharsLeft));
}
}
else
{
AppendTextNode(*m_pPaM->GetPoint());
- m_rDoc.getIDocumentContentOperations().InsertString(*m_pPaM, rAddString);
+ m_rDoc.getIDocumentContentOperations().InsertString(*m_pPaM, addString);
}
m_bReadTable = false;
@@ -3468,13 +3494,17 @@ bool SwWW8ImplReader::ReadChars(WW8_CP& rPos, WW8_CP nNextAttr, long nTextEnd,
nRequested = nMaxPossible;
}
- for (WW8_CP nCh = 0; nCh < nRequested; ++nCh)
+ if (!linguistic::IsControlChar(m_cSymbol)
+ || m_cSymbol == '\r' || m_cSymbol == '\n' || m_cSymbol == '\t')
{
- m_rDoc.getIDocumentContentOperations().InsertString( *m_pPaM, OUString(m_cSymbol) );
+ for (WW8_CP nCh = 0; nCh < nRequested; ++nCh)
+ {
+ m_rDoc.getIDocumentContentOperations().InsertString(*m_pPaM, OUString(m_cSymbol));
+ }
+ m_xCtrlStck->SetAttr(*m_pPaM->GetPoint(), RES_CHRATR_FONT);
+ m_xCtrlStck->SetAttr(*m_pPaM->GetPoint(), RES_CHRATR_CJK_FONT);
+ m_xCtrlStck->SetAttr(*m_pPaM->GetPoint(), RES_CHRATR_CTL_FONT);
}
- m_xCtrlStck->SetAttr( *m_pPaM->GetPoint(), RES_CHRATR_FONT );
- m_xCtrlStck->SetAttr( *m_pPaM->GetPoint(), RES_CHRATR_CJK_FONT );
- m_xCtrlStck->SetAttr( *m_pPaM->GetPoint(), RES_CHRATR_CTL_FONT );
}
m_pStrm->SeekRel(nRequested);
rPos = nEnd; // Ignore until attribute end
diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx
index 856923589c4b..4221eb3b454c 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -552,6 +552,8 @@ namespace sw
sal_Int32 GetPtContent() const { return mnPtContent; };
};
}
+
+ auto FilterControlChars(OUString const& rString) -> OUString;
}
class WW8FieldEntry
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index dbfa676e93f1..39e13b8cac5d 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -1947,7 +1947,8 @@ eF_ResT SwWW8ImplReader::Read_F_Symbol( WW8FieldDesc*, OUString& rStr )
if( aQ.isEmpty() )
return eF_ResT::TAGIGN; // -> no 0-char in text
- if (sal_Unicode cChar = static_cast<sal_Unicode>(aQ.toInt32()))
+ sal_Unicode const cChar = static_cast<sal_Unicode>(aQ.toInt32());
+ if (!linguistic::IsControlChar(cChar) || cChar == '\r' || cChar == '\n' || cChar == '\t')
{
if (!aName.isEmpty()) // Font Name set ?
{
@@ -2727,11 +2728,11 @@ void SwWW8ImplReader::Read_SubF_Ruby( WW8ReadFieldParams& rReadParam)
if ((nBegin != -1) && (nEnd != -1) && (nBegin < nEnd))
{
sText = sPart.copy(nBegin+1,nEnd-nBegin-1);
+ sText = sw::FilterControlChars(sText);
}
}
}
}
-
}
break;
}
More information about the Libreoffice-commits
mailing list