sw/qa/extras/ooxmlexport/data/tdf146955.odt       |binary
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx        |   12 ++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   12 +++++-------
 3 files changed, 17 insertions(+), 7 deletions(-)

New commits:
commit 73696a01224a3758bde686f32ec7e6f4c90877fe
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Wed May 25 11:57:13 2022 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Thu May 26 20:26:13 2022 +0200

    tdf#146955 DOCX import: fix SAX exception with footnotes
    
    (Likely broken) DOCX documents exported by Writer raised a SAX
    exception, when PopFootOrEndnote() tried to access to a
    not-existent footnote, because PushFootOrEndnote() failed to
    create that.
    
    Note: the original ODT contains hundreds of frames, and
    these and the text content of the document have been put
    into the TOC section during Writer's DOCX export, resulting a
    broken document.
    
    Regression from commit 9b39ce0e66acfe812e1d50e530dc2ccdef3e1357
    "tdf#76260 DOCX import: fix slow footnote import".
    
    Change-Id: I9e32feb0cae778a87f034a8b5c41989fec90899d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134934
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf146955.odt 
b/sw/qa/extras/ooxmlexport/data/tdf146955.odt
new file mode 100644
index 000000000000..c7a849f9b756
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf146955.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index d3804717e29c..fd6c560395b5 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -9,6 +9,7 @@
 
 #include <com/sun/star/beans/NamedValue.hpp>
 #include <com/sun/star/text/XBookmarksSupplier.hpp>
+#include <com/sun/star/text/XFootnotesSupplier.hpp>
 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
 #include <com/sun/star/text/XTextField.hpp>
 #include <com/sun/star/drawing/XShapes.hpp>
@@ -813,6 +814,17 @@ DECLARE_OOXMLEXPORT_TEST(testTdf144563, "tdf144563.docx")
     }
 }
 
+// broken test document?
+#if !defined(_WIN32)
+DECLARE_OOXMLEXPORT_TEST(testTdf146955, "tdf146955.odt")
+{
+    // import of a (broken?) DOCX export with dozens of frames raised a SAX 
exception,
+    // when the code tried to access to a non-existent footnote
+    uno::Reference<text::XFootnotesSupplier> xNotes(mxComponent, 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xNotes->getFootnotes()->getCount());
+}
+#endif
+
 DECLARE_OOXMLEXPORT_TEST(testTdf144668, "tdf144668.odt")
 {
     uno::Reference<beans::XPropertySet> xPara1(getParagraph(1, u"level1"), 
uno::UNO_QUERY);
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 1371b7cc0e32..4e769e15b0cf 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -3504,13 +3504,11 @@ void DomainMapper_Impl::PopFootOrEndnote()
         uno::Reference< text::XFootnote > xFootnoteFirst, xFootnoteLast;
         auto xFootnotes = xFootnotesSupplier->getFootnotes();
         auto xEndnotes = xEndnotesSupplier->getEndnotes();
-        if (IsInFootnote())
-            xFootnotes->getByIndex(xFootnotes->getCount()-1) >>= xFootnoteLast;
-        else
-            xEndnotes->getByIndex(xEndnotes->getCount()-1) >>= xFootnoteLast;
-        if ( ( ( IsInFootnote() && xFootnotes->getCount() > 1 ) ||
-             ( !IsInFootnote() && xEndnotes->getCount() > 1 ) ) &&
-                        xFootnoteLast->getLabel().isEmpty() )
+        if ( ( ( IsInFootnote() && xFootnotes->getCount() > 1 &&
+                       ( xFootnotes->getByIndex(xFootnotes->getCount()-1) >>= 
xFootnoteLast ) ) ||
+               ( !IsInFootnote() && xEndnotes->getCount() > 1 &&
+                       ( xEndnotes->getByIndex(xEndnotes->getCount()-1) >>= 
xFootnoteLast ) )
+             ) && xFootnoteLast->getLabel().isEmpty() )
         {
             // copy content of the first remaining temporary footnote
             if ( IsInFootnote() )

Reply via email to