diff options
author | Tor Lillqvist <tml@collabora.com> | 2014-07-25 04:13:44 -0700 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2014-07-25 14:23:53 +0300 |
commit | 355f8a3c6540acc01c6874385fb63ce23ffa8c3f (patch) | |
tree | 53dfedf0d0f032d62063051c8ba95b6e82b75d05 | |
parent | Restore SvStream::PutBack(char) (diff) | |
download | core-355f8a3c6540acc01c6874385fb63ce23ffa8c3f.tar.gz core-355f8a3c6540acc01c6874385fb63ce23ffa8c3f.zip |
Handle broken RTF files that have multiple top-level (\rtf) groups
There exists in the wild RTF files that have two top-level groups
(starting with the \rtf control word). Ignore the group-end '}' and
the following group-start '{' in that case. Horrible hack, yes. But
Word does not seem to require correctly formed RTF either, it handles
this kind of files. So we should too. At least in this case of
brokenness.
Change-Id: Idd26a82f1da1e1f873c158367469eca7d9b0d652
-rw-r--r-- | writerfilter/source/rtftok/rtftokenizer.cxx | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/writerfilter/source/rtftok/rtftokenizer.cxx b/writerfilter/source/rtftok/rtftokenizer.cxx index 3515c8b10268..fa4e23437199 100644 --- a/writerfilter/source/rtftok/rtftokenizer.cxx +++ b/writerfilter/source/rtftok/rtftokenizer.cxx @@ -122,6 +122,38 @@ int RTFTokenizer::resolveParse() return ret; break; case '}': + if (m_nGroup == 1) + { + // Handle bogus RTF documents that have + // several top-level groups: Ignore the group + // end and following group start characters, + // i.e. pretend it is one group. + bool bSkipping(true), bDidIt(false); + char oldch(ch); + while (bSkipping && ((Strm() >> ch, !Strm().IsEof()))) + { + switch (ch) + { + case 0x0d: + break; // ignore this + case 0x0a: + m_nLineNumber++; + m_nLineStartPos = nCurrentPos; + break; + case '{': + bSkipping = false; + bDidIt = true; + break; + default: + Strm().PutBack(ch); + ch = oldch; + bSkipping = false; + break; + } + } + if (bDidIt) + break; + } ret = m_rImport.popState(); if (ret) return ret; @@ -295,7 +327,7 @@ int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam) { if (m_rImport.getState().nDestinationState == DESTINATION_SKIP) return 0; - /*SAL_INFO("writefilter", OSL_THIS_FUNC << ": keyword '\\" << rKeyword.getStr() << + /*SAL_INFO("writerfilter", "keyword '\\" << rKeyword.getStr() << "' with param? " << (bParam ? 1 : 0) <<" param val: '" << (bParam ? nParam : 0) << "'");*/ RTFSymbol aSymbol; aSymbol.sKeyword = rKeyword.getStr(); |