summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2020-06-08 13:05:27 +0200
committerMichael Stahl <michael.stahl@cib.de>2020-06-09 10:40:13 +0200
commitc9d842ddc54b701eb57cc79032fabcf14391a3a1 (patch)
tree7701534bcc93f99c00695392197c53d2ed5be218
parent577dd32b1c4eb0a4cff574fbabca987cb52b831b (diff)
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@cib.de> (cherry picked from commit 27151ccf2305eac4192f8c4ceeee267170096a19) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95824 Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx16
1 files changed, 11 insertions, 5 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 1130007df6f7..76ba72b32aad 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2212,6 +2212,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;
@@ -2225,6 +2226,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,
@@ -2252,15 +2258,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");
}
}
}