sw/qa/extras/uiwriter/data/simplefooter.docx |binary
 sw/qa/extras/uiwriter/uiwriter7.cxx          |   24 ++++++++++++++++++++++++
 sw/source/filter/ww8/wrtw8sty.cxx            |    8 ++++++++
 3 files changed, 32 insertions(+)

New commits:
commit 3eda5d345f14f8926358df7b425c452a8a165c7d
Author:     Hossein <hoss...@libreoffice.org>
AuthorDate: Fri May 20 15:20:40 2022 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon May 23 16:29:54 2022 +0200

    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 <vmik...@collabora.com>

diff --git a/sw/qa/extras/uiwriter/data/simplefooter.docx 
b/sw/qa/extras/uiwriter/data/simplefooter.docx
new file mode 100644
index 000000000000..006c85ab7cc8
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/simplefooter.docx differ
diff --git a/sw/qa/extras/uiwriter/uiwriter7.cxx 
b/sw/qa/extras/uiwriter/uiwriter7.cxx
index 3815713dc877..0cb70e91076b 100644
--- a/sw/qa/extras/uiwriter/uiwriter7.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter7.cxx
@@ -24,6 +24,7 @@
 #include <AnnotationWin.hxx>
 #include <com/sun/star/awt/FontUnderline.hpp>
 
+#include <svx/hdft.hxx>
 #include <svx/svdpage.hxx>
 #include <svx/svdview.hxx>
 #include <svx/svxids.hrc>
@@ -2751,6 +2752,29 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf117225)
     CPPUNIT_ASSERT_EQUAL(nExpected, nActual);
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, 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_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx 
b/sw/source/filter/ww8/wrtw8sty.cxx
index 44d437dbf772..6e9053401606 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -2080,6 +2080,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
@@ -2087,6 +2091,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();
     }
 

Reply via email to