[Libreoffice-commits] core.git: writerfilter/source

Michael Stahl (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 8 15:51:13 UTC 2020


 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

New commits:
commit 27151ccf2305eac4192f8c4ceeee267170096a19
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Jun 8 13:05:27 2020 +0200
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Mon Jun 8 17:50:37 2020 +0200

    tdf#132596 writerfilter: fix paste of RTF with header/footer
    
    The problem is that writerfilter inserts the content of header/footer
    into the body text, but then DomainMapper_Impl::PopPageHeaderFooter()
    calls RemoveLastParagraph() and deletes a body paragraph containing a
    fieldmark, and then in Undo some SwHistoryTextFieldmark can't find it,
    and since ffb26b81e1c7ff1d64959200247bb2edd5a569da this crashes.
    
    This is because of the borked error handling in
    DomainMapper_Impl::PushPageHeaderFooter(); the
    m_xBodyText->createTextCursorByRange() call throws an exception that is
    swallowed, so the m_aTextAppendStack doesn't have an entry containing
    the position in the header.
    
    To fix the error handling, set m_bDiscardHeaderFooter = false only when
    everything was successful.
    
    Also fix the call to be xText->createTextCursorByRange instead
    (this is a regression from 232ad2f2588beff50cb5c1f3b689c581ba317583).
    
    Then it turns out that Undo still crashes, because sw can't Undo
    changes of header/footer content, so just return early unless it's
    a new document.
    
    Change-Id: Ie5aeb45447c5fbd4b3ae15c4cffb9800583a6d1d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95797
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>

diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 97dc761bff91..0fd359de5af6 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2369,6 +2369,7 @@ void DomainMapper_Impl::PushPageHeaderFooter(bool bHeader, SectionPropertyMap::P
     const PropertyIds ePropTextLeft = bHeader? PROP_HEADER_TEXT_LEFT: PROP_FOOTER_TEXT_LEFT;
     const PropertyIds ePropText = bHeader? PROP_HEADER_TEXT: PROP_FOOTER_TEXT;
 
+    m_bDiscardHeaderFooter = true;
     m_eInHeaderFooterImport
         = bHeader ? HeaderFooterImportState::header : HeaderFooterImportState::footer;
 
@@ -2382,6 +2383,11 @@ void DomainMapper_Impl::PushPageHeaderFooter(bool bHeader, SectionPropertyMap::P
         // content is not copied from the previous section
         pSectionContext->ClearHeaderFooterLinkToPrevious(bHeader, eType);
 
+        if (!m_bIsNewDoc)
+        {
+            return; // TODO sw cannot Undo insert header/footer without crashing
+        }
+
         uno::Reference< beans::XPropertySet > xPageStyle =
             pSectionContext->GetPageStyle(
                 *this,
@@ -2409,15 +2415,15 @@ void DomainMapper_Impl::PushPageHeaderFooter(bool bHeader, SectionPropertyMap::P
                 xPageStyle->getPropertyValue(getPropertyName(bLeft? ePropTextLeft: ePropText)) >>= xText;
 
                 m_aTextAppendStack.push(TextAppendContext(uno::Reference< text::XTextAppend >(xText, uno::UNO_QUERY_THROW),
-                            m_bIsNewDoc? uno::Reference<text::XTextCursor>(): m_xBodyText->createTextCursorByRange(xText->getStart())));
-            }
-            else
-            {
-                m_bDiscardHeaderFooter = true;
+                    m_bIsNewDoc
+                        ? uno::Reference<text::XTextCursor>()
+                        : xText->createTextCursorByRange(xText->getStart())));
+                m_bDiscardHeaderFooter = false; // set only on success!
             }
         }
         catch( const uno::Exception& )
         {
+            DBG_UNHANDLED_EXCEPTION("writerfilter.dmapper");
         }
     }
 }


More information about the Libreoffice-commits mailing list