summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2019-11-12 18:57:58 +0100
committerVasily Melenchuk <vasily.melenchuk@cib.de>2021-04-13 15:55:06 +0300
commitc0fd4549d478350bdbdd75a070be013066588e71 (patch)
tree47d701d6e406a37e4412e100276ab966b2b6d016
parent0f7130769d3e6578c4cd718ed8823c0e1a821dd8 (diff)
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@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit 7ecda38cdaa2361e8510bf3e7206863c4936deab) Reviewed-on: https://gerrit.libreoffice.org/82759 (cherry picked from commit d494a4c0ead7db481757d8d67fbce9e1b02e65df)
-rw-r--r--sw/qa/core/data/ww5/pass/ofz18526-1.docbin0 -> 781 bytes
-rw-r--r--sw/source/filter/ww8/ww8par.cxx54
-rw-r--r--sw/source/filter/ww8/ww8par.hxx2
-rw-r--r--sw/source/filter/ww8/ww8par5.cxx6
4 files changed, 48 insertions, 14 deletions
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
--- /dev/null
+++ b/sw/qa/core/data/ww5/pass/ofz18526-1.doc
Binary files differ
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 98569b059863..efb4b2942920 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -115,6 +115,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>
@@ -3391,13 +3393,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();
@@ -3411,21 +3437,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;
@@ -3451,13 +3477,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 ee5a8b68b795..676745d07078 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -550,6 +550,8 @@ namespace sw
sal_Int32 GetPtContent() { 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 1d2430db8d69..963364531d19 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -34,6 +34,7 @@
#include <svl/urihelper.hxx>
#include <svl/zforlist.hxx>
#include <svl/zformat.hxx>
+#include <svl/lngmisc.hxx>
#include <sfx2/linkmgr.hxx>
#include <rtl/character.hxx>
#include <unotools/charclass.hxx>
@@ -1906,7 +1907,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 ?
{
@@ -2686,11 +2688,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;
}