sw/qa/uitest/data/tdf146248.docx               |binary
 sw/qa/uitest/writer_tests4/insertPageHeader.py |   14 ++++++++++++++
 sw/source/core/unocore/unoobj2.cxx             |    3 +++
 3 files changed, 17 insertions(+)

New commits:
commit c617aafc370209b8807ba6e0eba2762595595a0f
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Mon Jan 9 15:07:27 2023 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Wed Jan 11 16:07:57 2023 +0000

    tdf#146248 sw: fix crash at Undo of hiding page header/footer
    
    When Same content on first page is enabled, Undo could result
    crashing after hiding header/footer with its local menu.
    
    Note: the problem could occur in DOCX more frequently,
    because of special handling of its header/footer,
    see commit f5dc6b11d2218d94c9effe7a1ab418d0133da5e3
    "tdf#140117 sw UI: keep headers/footers when inactive".
    
    Manual test: load the unit test document, delete
    the header with its blue local menu (not with the Page
    Style dialog window!), and press Undo. (The Python
    UITest does the same, but with dispatcher calls).
    
    Regression from commit 65e52cb61d74b0c71b45b63b2da131bc6b621104
    "tdf#141613 sw: fix crash at header/footer undo".
    
    Change-Id: If89d5af2e0d123d6913dfc6a4bea1ddbaf3bd80b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145244
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit cec3c719303decd3b811a328fabd71d8c4e5ba3b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145300
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/qa/uitest/data/tdf146248.docx b/sw/qa/uitest/data/tdf146248.docx
new file mode 100644
index 000000000000..2b5ed2959f94
Binary files /dev/null and b/sw/qa/uitest/data/tdf146248.docx differ
diff --git a/sw/qa/uitest/writer_tests4/insertPageHeader.py 
b/sw/qa/uitest/writer_tests4/insertPageHeader.py
index 6516a31dab4d..406671021881 100644
--- a/sw/qa/uitest/writer_tests4/insertPageHeader.py
+++ b/sw/qa/uitest/writer_tests4/insertPageHeader.py
@@ -8,6 +8,7 @@
 #
 
 from uitest.framework import UITestCase
+from uitest.uihelper.common import get_url_for_data_file
 
 class WriterInsertPageHeader(UITestCase):
 
@@ -61,4 +62,17 @@ class WriterInsertPageHeader(UITestCase):
 
             self.delete_header()
 
+    def test_tdf146248(self):
+        with self.ui_test.load_file(get_url_for_data_file("tdf146248.docx")):
+
+            self.delete_header()
+
+            # crashed before
+            self.xUITest.executeCommand(".uno:Undo")
+
+            document = self.ui_test.get_component()
+            self.assertEqual(
+                document.StyleFamilies.PageStyles.Standard.HeaderIsOn, True)
+
+
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/core/unocore/unoobj2.cxx 
b/sw/source/core/unocore/unoobj2.cxx
index 538ea72430b0..e5fefbc0e376 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -1191,6 +1191,9 @@ lcl_IsStartNodeInFormat(const bool bHeader, SwStartNode 
const *const pSttNode,
         if (pHeadFootFormat)
         {
             const SwFormatContent& rFlyContent = pHeadFootFormat->GetContent();
+            // tdf#146248 avoid Undo crash at shared first page
+            if ( !rFlyContent.GetContentIdx() )
+                return false;
             const SwNode& rNode = rFlyContent.GetContentIdx()->GetNode();
             SwStartNode const*const pCurSttNode = rNode.FindSttNodeByType(
                 bHeader ? SwHeaderStartNode : SwFooterStartNode);

Reply via email to