[Libreoffice-commits] .: writerfilter/source

Cédric Bosdonnat cbosdo at kemper.freedesktop.org
Tue Dec 13 06:17:10 PST 2011


 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   25 +++++++++++++++++++++----
 writerfilter/source/rtftok/rtfdocumentimpl.hxx |    1 +
 2 files changed, 22 insertions(+), 4 deletions(-)

New commits:
commit e7fc2624a1aa4aaaf29fe302a30cc43a297106e5
Author: Cédric Bosdonnat <cedric.bosdonnat.ooo at free.fr>
Date:   Tue Dec 13 14:22:44 2011 +0100

    n#703032: Fixed an RTF import crash when handling formdata in non-FORM fields

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 8b25e4e..2b6aa61 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -288,6 +288,7 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
     m_aStyleTableEntries(),
     m_nCurrentStyleIndex(0),
     m_bEq(false),
+    m_bFormField(false),
     m_bWasInFrame(false),
     m_bIsInFrame(false),
     m_aUnicodeBuffer()
@@ -969,18 +970,32 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
             break;
         case RTF_FLDINST:
             {
+                // Look for the field type
                 sal_Int32 nPos = Strm().Tell();
                 OStringBuffer aBuf;
                 char ch;
-                for (int i = 0; i < 4; ++i)
+                bool bFoundCode = false;
+                bool bInKeyword = false;
+                while (!bFoundCode && ch != '}')
                 {
                     Strm() >> ch;
-                    aBuf.append(ch);
+                    if ('\\' == ch)
+                        bInKeyword = true;
+                    if (!bInKeyword  && isalnum(ch))
+                        aBuf.append(ch);
+                    else if (bInKeyword && isspace(ch))
+                        bInKeyword = false;
+                    if (aBuf.getLength() > 0 && !isalnum(ch))
+                        bFoundCode = true;
                 }
                 Strm().Seek(nPos);
 
+                // Form data should be handled only for form fields if any
+                if (aBuf.toString().indexOf(OString("FORM")) != -1 )
+                    m_bFormField = true;
+
                 // EQ fields are not really fields in fact.
-                if (aBuf.toString().equals("{ EQ"))
+                if (aBuf.toString().equals("EQ"))
                     m_bEq = true;
                 else
                 {
@@ -2871,7 +2886,7 @@ int RTFDocumentImpl::popState()
         RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aDestinationText.makeStringAndClear()));
         m_aFormfieldSprms->push_back(make_pair(NS_ooxml::LN_CT_FFDDList_listEntry, pValue));
     }
-    else if (m_aStates.top().nDestinationState == DESTINATION_DATAFIELD)
+    else if (m_aStates.top().nDestinationState == DESTINATION_DATAFIELD && m_bFormField)
     {
         OString aStr = OUStringToOString(m_aStates.top().aDestinationText.makeStringAndClear(), m_aStates.top().nCurrentEncoding);
         // decode hex dump
@@ -2914,6 +2929,8 @@ int RTFDocumentImpl::popState()
         m_aFormfieldSprms->push_back(make_pair(NS_ooxml::LN_CT_FFData_name, pNValue));
         RTFValue::Pointer_t pDValue(new RTFValue(OStringToOUString(aDefaultText, m_aStates.top().nCurrentEncoding)));
         m_aFormfieldSprms->push_back(make_pair(NS_ooxml::LN_CT_FFTextInput_default, pDValue));
+
+        m_bFormField = false;
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_CREATIONTIME && m_xDocumentProperties.is())
         m_xDocumentProperties->setCreationDate(lcl_getDateTime(m_aStates));
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 729e5e5..4370d9a 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -425,6 +425,7 @@ namespace writerfilter {
                 RTFReferenceTable::Entries_t m_aStyleTableEntries;
                 int m_nCurrentStyleIndex;
                 bool m_bEq;
+                bool m_bFormField;
                 /// If we were in a frame.
                 bool m_bWasInFrame;
                 /// If a frame start token is already sent to dmapper (nesting them is not OK).


More information about the Libreoffice-commits mailing list