diff options
author | Hossein <hossein@libreoffice.org> | 2022-05-20 15:20:40 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-05-24 09:35:49 +0200 |
commit | 7b09579295579045c4ad76578df09356f3d5b8d0 (patch) | |
tree | 16c51c55162ce8ba7b91730afb51708fd34919c7 | |
parent | 6f6d61ea5d7700fb18bfb49c6e1d16a55944e581 (diff) |
tdf#149184 DOCX: fix crash removing footer, then saving to doc
When openeing the simplefooter.docx, after removing the footer and
exporting to .doc, LibreOffice crashes. This regression was
introduced with 88e6a1bfeac86e0c89d2ff08c908c2b5ae061177 which is
titled: "DOCX: export hidden (shared) headers/footers".
The current patch fixes this problem by checking to see if the header
or footer text is there or not.
A unit test is added to avoid this problem in the future. One can run
the test with:
make CPPUNIT_TEST_NAME="testTdf149184" -sr CppunitTest_sw_uiwriter7
Change-Id: I5586561677b3c490e49b4b10bd987aecdf3fc134
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134684
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134829
-rw-r--r-- | sw/qa/extras/uiwriter/data/simplefooter.docx | bin | 0 -> 18174 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 22 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtw8sty.cxx | 8 |
3 files changed, 30 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/data/simplefooter.docx b/sw/qa/extras/uiwriter/data/simplefooter.docx Binary files differnew file mode 100644 index 000000000000..006c85ab7cc8 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/simplefooter.docx diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index b7593759971b..0aea38d4bbe7 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -50,6 +50,7 @@ #include <com/sun/star/awt/FontUnderline.hpp> #include <vcl/TypeSerializer.hxx> +#include <svx/hdft.hxx> #include <svx/svdpage.hxx> #include <svx/svdview.hxx> #include <svl/itemiter.hxx> @@ -290,6 +291,7 @@ public: void testTdf92648(); void testTdf103978_backgroundTextShape(); void testTdf117225(); + void testTdf149184(); CPPUNIT_TEST_SUITE(SwUiWriterTest); CPPUNIT_TEST(testReplaceForward); @@ -411,6 +413,7 @@ public: CPPUNIT_TEST(testTdf92648); CPPUNIT_TEST(testTdf103978_backgroundTextShape); CPPUNIT_TEST(testTdf117225); + CPPUNIT_TEST(testTdf149184); CPPUNIT_TEST_SUITE_END(); private: @@ -4691,6 +4694,25 @@ void SwUiWriterTest::testTdf117225() CPPUNIT_ASSERT_EQUAL(nExpected, nActual); } +void SwUiWriterTest::testTdf149184() +{ + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "simplefooter.docx"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + // Removing the footer for all styles + pWrtShell->ChangeHeaderOrFooter(u"", false, false, false); + // export to simplefooter.doc + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("MS Word 97")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + // Without the fix in place, the test fails with: + // [CUT] sw_uiwriter7 + // Segmentation fault (core dumped) + // [_RUN_____] testTdf149184::TestBody + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); +} CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx index 9f103627d576..4126b9f88a50 100644 --- a/sw/source/filter/ww8/wrtw8sty.cxx +++ b/sw/source/filter/ww8/wrtw8sty.cxx @@ -2087,6 +2087,10 @@ void MSWordExportBase::WriteHeaderFooterText( const SwFormat& rFormat, bool bHea m_bHasHdr = true; const SwFormatHeader& rHd = rFormat.GetHeader(); OSL_ENSURE( rHd.GetHeaderFormat(), "Header text is not here" ); + + if ( !rHd.GetHeaderFormat() ) + return; + pContent = &rHd.GetHeaderFormat()->GetContent(); } else @@ -2094,6 +2098,10 @@ void MSWordExportBase::WriteHeaderFooterText( const SwFormat& rFormat, bool bHea m_bHasFtr = true; const SwFormatFooter& rFt = rFormat.GetFooter(); OSL_ENSURE( rFt.GetFooterFormat(), "Footer text is not here" ); + + if ( !rFt.GetFooterFormat() ) + return; + pContent = &rFt.GetFooterFormat()->GetContent(); } |