[Libreoffice-commits] .: Branch 'libreoffice-3-5' - writerfilter/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Tue Dec 13 06:38:41 PST 2011


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

New commits:
commit 742a9d518542d5274389315f79c66162f669d4af
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
    
    Signed-off-by: Miklos Vajna <vmiklos at frugalware.org>

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 718d60e..57d8b9b 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -290,6 +290,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()
@@ -971,18 +972,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
                 {
@@ -2881,7 +2896,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
@@ -2924,6 +2939,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