[Libreoffice-commits] core.git: sw/CppunitTest_sw_core_text.mk sw/Module_sw.mk sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri Nov 15 15:41:24 UTC 2019


 sw/CppunitTest_sw_core_text.mk             |   68 ++++++++++++++
 sw/Module_sw.mk                            |    1 
 sw/qa/core/text/data/footnote-connect.fodt |  132 +++++++++++++++++++++++++++++
 sw/qa/core/text/text.cxx                   |   51 +++++++++++
 sw/source/core/text/txtftn.cxx             |   10 +-
 5 files changed, 259 insertions(+), 3 deletions(-)

New commits:
commit 0e0bad1a6a3affa2b3fd82cc3834ae03ea7bc1d5
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Nov 15 12:14:09 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Nov 15 16:39:48 2019 +0100

    tdf#128736 sw ContinuousEndnotes: fix use-after-free on text frame join
    
    Regression from commit 61cf196631a2a846e0d3b8b83c0805cf4d1d14b2 (sw
    ContinuousEndnotes: fix moving them to the previous page, 2019-10-25),
    the problem was that the SwFootnoteFrame::mpReference was not updated on
    frame split. This meant that by the time the frame was joined,
    SwTextFrame::JoinFrame() thought that the follow has no footnotes, so
    the footnote reference was not updated, resulting in a dangling pointer.
    
    Fix the problem by going back to using bEnd for endnotes (both the Word
    compat and the normal case), this means that
    SwTextFrame::ConnectFootnote() will invoke
    SwFootnoteBossFrame::ChangeFootnoteRef(), fixing the dangling pointer.
    
    Then fix the original problem differently: similar to the in-section
    endnotes, just remove + append them, this makes sure that the endnotes
    (in the Word compat case) move to a previous page on page delete.
    
    Change-Id: Ia1b8e54b4a0b0f385c703f8e7016011c3ac57a03
    Reviewed-on: https://gerrit.libreoffice.org/82778
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/sw/CppunitTest_sw_core_text.mk b/sw/CppunitTest_sw_core_text.mk
new file mode 100644
index 000000000000..9fe4fadbf357
--- /dev/null
+++ b/sw/CppunitTest_sw_core_text.mk
@@ -0,0 +1,68 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_core_text))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_text))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_core_text, \
+    sw/qa/core/text/text \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_core_text, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    sal \
+    sfx \
+    sw \
+    test \
+    unotest \
+    utl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_core_text,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_core_text,\
+    -I$(SRCDIR)/sw/inc \
+    -I$(SRCDIR)/sw/source/core/inc \
+    -I$(SRCDIR)/sw/source/uibase/inc \
+    -I$(SRCDIR)/sw/qa/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_core_text,\
+	udkapi \
+	offapi \
+	oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_core_text))
+$(eval $(call gb_CppunitTest_use_vcl,sw_core_text))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_core_text,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_core_text,\
+    officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_core_text))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_text, \
+    modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_text))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index b16a4aea6e16..2dbd5f161f22 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -104,6 +104,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_accessible_relation_set \
     CppunitTest_sw_apitests \
     CppunitTest_sw_unowriter \
+    CppunitTest_sw_core_text \
 ))
 
 ifneq ($(DISABLE_GUI),TRUE)
diff --git a/sw/qa/core/text/data/footnote-connect.fodt b/sw/qa/core/text/data/footnote-connect.fodt
new file mode 100644
index 000000000000..dd26db98c9e0
--- /dev/null
+++ b/sw/qa/core/text/data/footnote-connect.fodt
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:css3t="http://www.w3.org/TR/css3-text/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.
 0" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ooo="http://openoffice.org/2004/office" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:rpt="http://op
 enoffice.org/2005/report" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+  <office:settings>
+    <config:config-item-set config:name="ooo:configuration-settings">
+      <config:config-item config:name="UseFormerTextWrapping" config:type="boolean">false</config:config-item>
+      <config:config-item config:name="ContinuousEndnotes" config:type="boolean">true</config:config-item>
+    </config:config-item-set>
+  </office:settings>
+  <office:font-face-decls>
+    <style:font-face style:name="Liberation Sans" svg:font-family="'Liberation Sans'" style:font-family-generic="roman" style:font-pitch="variable"/>
+  </office:font-face-decls>
+  <office:styles>
+    <style:default-style style:family="graphic">
+    </style:default-style>
+    <style:default-style style:family="paragraph">
+      <style:text-properties style:font-name="Liberation Sans" fo:font-size="12pt"/>
+    </style:default-style>
+    <style:default-style style:family="table">
+      <style:table-properties table:border-model="collapsing"/>
+    </style:default-style>
+    <style:default-style style:family="table-row">
+      <style:table-row-properties fo:keep-together="auto"/>
+    </style:default-style>
+    <style:style style:name="Standard" style:family="paragraph" style:class="text">
+      <style:text-properties style:font-name="Liberation Sans" fo:font-size="12pt"/>
+    </style:style>
+    <style:style style:name="Endnote" style:family="paragraph" style:parent-style-name="Standard" style:class="extra">
+      <style:text-properties fo:font-size="10pt" style:font-size-asian="10pt"/>
+    </style:style>
+    <style:style style:name="Frame" style:family="graphic">
+    </style:style>
+  </office:styles>
+  <office:automatic-styles>
+    <style:style style:name="Table6" style:family="table">
+      <style:table-properties style:width="15.983cm" table:align="margins" style:writing-mode="lr-tb"/>
+    </style:style>
+    <style:style style:name="Table6.A" style:family="table-column">
+      <style:table-column-properties style:column-width="15.983cm" style:rel-column-width="65535*"/>
+    </style:style>
+    <style:style style:name="Table6.1" style:family="table-row">
+      <style:table-row-properties fo:keep-together="auto"/>
+    </style:style>
+    <style:style style:name="Table6.A1" style:family="table-cell">
+      <style:table-cell-properties style:vertical-align="top" fo:padding-left="0cm" fo:padding-right="0cm" fo:padding-top="0cm" fo:padding-bottom="0.199cm" fo:border="none" style:writing-mode="lr-tb"/>
+    </style:style>
+    <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard" style:master-page-name="Standard">
+    </style:style>
+    <style:style style:name="P3" style:family="paragraph" style:parent-style-name="Standard">
+      <style:paragraph-properties fo:break-before="page"/>
+    </style:style>
+    <style:style style:name="fr1" style:family="graphic" style:parent-style-name="Frame">
+      <style:graphic-properties fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-top="0cm" fo:margin-bottom="0cm" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" style:vertical-pos="from-top" style:vertical-rel="page" style:horizontal-pos="left" style:horizontal-rel="page-content" fo:background-color="#ffffff" style:background-transparency="100%" draw:fill="solid" draw:fill-color="#ffffff" draw:opacity="0%" fo:padding="0cm" fo:border="none" style:writing-mode="lr-tb" draw:wrap-influence-on-position="once-successive" loext:allow-overlap="true"/>
+    </style:style>
+    <style:page-layout style:name="pm1">
+      <style:page-layout-properties fo:page-width="21.001cm" fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" fo:margin-top="1.27cm" fo:margin-bottom="3.071cm" fo:margin-left="3cm" fo:margin-right="2cm" style:writing-mode="lr-tb" style:layout-grid-color="#c0c0c0" style:layout-grid-lines="39" style:layout-grid-base-height="0.635cm" style:layout-grid-ruby-height="0cm" style:layout-grid-mode="none" style:layout-grid-ruby-below="false" style:layout-grid-print="false" style:layout-grid-display="false" style:layout-grid-base-width="0.423cm" style:layout-grid-snap-to="true" style:footnote-max-height="0cm">
+        <style:footnote-sep style:width="0.018cm" style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" style:line-style="solid" style:adjustment="left" style:rel-width="25%" style:color="#000000"/>
+      </style:page-layout-properties>
+      <style:header-style/>
+      <style:footer-style>
+        <style:header-footer-properties fo:min-height="0.653cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-top="0.554cm" style:dynamic-spacing="true"/>
+      </style:footer-style>
+    </style:page-layout>
+  </office:automatic-styles>
+  <office:master-styles>
+    <style:master-page style:name="Standard" style:page-layout-name="pm1">
+      <style:footer>
+        <text:p></text:p>
+      </style:footer>
+      <loext:footer-first>
+        <text:p text:style-name="Footer"><draw:frame draw:style-name="fr1" draw:name="Frame1" text:anchor-type="paragraph" svg:y="25.506cm" svg:width="15.983cm" draw:z-index="0"><draw:text-box fo:min-height="0.058cm"><table:table table:name="Table6" table:style-name="Table6"><table:table-column table:style-name="Table6.A"/><table:table-row table:style-name="Table6.1"><table:table-cell table:style-name="Table6.A1" office:value-type="string"><text:p text:style-name="Standard">A1</text:p></table:table-cell></table:table-row></table:table></draw:text-box></draw:frame></text:p>
+      </loext:footer-first>
+    </style:master-page>
+  </office:master-styles>
+  <office:body>
+    <office:text text:use-soft-page-breaks="true">
+      <text:p text:style-name="P1">P01</text:p>
+      <text:p text:style-name="Standard">P02</text:p>
+      <text:p text:style-name="Standard">P03</text:p>
+      <text:p text:style-name="Standard">P04</text:p>
+      <text:p text:style-name="Standard">P05</text:p>
+      <text:p text:style-name="Standard">P06</text:p>
+      <text:p text:style-name="Standard">P07</text:p>
+      <text:p text:style-name="Standard">P08</text:p>
+      <text:p text:style-name="Standard">P09</text:p>
+      <text:p text:style-name="Standard">P10</text:p>
+      <text:p text:style-name="Standard">P11</text:p>
+      <text:p text:style-name="Standard">P12</text:p>
+      <text:p text:style-name="Standard">P13</text:p>
+      <text:p text:style-name="Standard">P14</text:p>
+      <text:p text:style-name="Standard">P15</text:p>
+      <text:p text:style-name="Standard">P16</text:p>
+      <text:p text:style-name="Standard">P17</text:p>
+      <text:p text:style-name="Standard">P18</text:p>
+      <text:p text:style-name="Standard">P19</text:p>
+      <text:p text:style-name="Standard">P20</text:p>
+      <text:p text:style-name="Standard">P21</text:p>
+      <text:p text:style-name="Standard">P22</text:p>
+      <text:p text:style-name="Standard">P23</text:p>
+      <text:p text:style-name="Standard">P24</text:p>
+      <text:p text:style-name="Standard">P25</text:p>
+      <text:p text:style-name="Standard">P26</text:p>
+      <text:p text:style-name="Standard">P27</text:p>
+      <text:p text:style-name="Standard">P28</text:p>
+      <text:p text:style-name="Standard">P29</text:p>
+      <text:p text:style-name="Standard">P30</text:p>
+      <text:p text:style-name="Standard">P31</text:p>
+      <text:p text:style-name="Standard">P32</text:p>
+      <text:p text:style-name="Standard">P33</text:p>
+      <text:p text:style-name="Standard">P34</text:p>
+      <text:p text:style-name="Standard">P35</text:p>
+      <text:p text:style-name="Standard">P36</text:p>
+      <text:p text:style-name="Standard">P37</text:p>
+      <text:p text:style-name="Standard">P38</text:p>
+      <text:p text:style-name="Standard"/>
+      <text:p text:style-name="Standard"/>
+      <text:p text:style-name="Standard"/>
+      <text:p text:style-name="P3">P2P01</text:p>
+      <text:p text:style-name="Standard">P2P02</text:p>
+      <text:p text:style-name="Standard">P2P03</text:p>
+      <text:p text:style-name="Standard">P2P04</text:p>
+      <text:p text:style-name="Standard">P2P05</text:p>
+      <text:p text:style-name="Standard">P2P06</text:p>
+      <text:p text:style-name="Standard">P2P07</text:p>
+      <text:p text:style-name="Standard">P2P08</text:p>
+      <text:p text:style-name="Standard">P2P09</text:p>
+      <text:p text:style-name="Standard">P2P10</text:p>
+      <text:p text:style-name="Standard">P2P11</text:p>
+      <text:p text:style-name="Standard">P2P12<text:note text:id="ftn1" text:note-class="endnote"><text:note-citation>1</text:note-citation><text:note-body></text:note-body></text:note> First line<text:line-break/>second line</text:p>
+      <text:p text:style-name="P3"/>
+    </office:text>
+  </office:body>
+</office:document>
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
new file mode 100644
index 000000000000..8074cbc9f45e
--- /dev/null
+++ b/sw/qa/core/text/text.cxx
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+#include <wrtsh.hxx>
+
+static char const DATA_DIRECTORY[] = "/sw/qa/core/text/data/";
+
+/// Covers sw/source/core/text/ fixes.
+class SwCoreTextTest : public SwModelTestBase
+{
+public:
+    SwDoc* createDoc(const char* pName = nullptr);
+};
+
+SwDoc* SwCoreTextTest::createDoc(const char* pName)
+{
+    load(DATA_DIRECTORY, pName);
+
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    return pTextDoc->GetDocShell()->GetDoc();
+}
+
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testFootnoteConnect)
+{
+    SwDoc* pDoc = createDoc("footnote-connect.fodt");
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    // Jump to the start of the next page.
+    pWrtShell->SttNxtPg();
+    // Remove the page break.
+    pWrtShell->DelLeft();
+    // Split the multi-line text frame, containing an endnote.
+    pWrtShell->DelLeft();
+    // Join the split text frame.
+    pWrtShell->DelLeft();
+    // Turn the 3 page document into a 2 page one, so the endnote frame is moved.
+    // Without the accompanying fix in place, this test would have crashed due to a use-after-free
+    // in SwFootnoteFrame::GetRef().
+    pWrtShell->DelLeft();
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/txtftn.cxx b/sw/source/core/text/txtftn.cxx
index 9bc253768349..4ca6938e82f3 100644
--- a/sw/source/core/text/txtftn.cxx
+++ b/sw/source/core/text/txtftn.cxx
@@ -585,7 +585,7 @@ void SwTextFrame::ConnectFootnote( SwTextFootnote *pFootnote, const SwTwips nDea
     // See if pFootnote is an endnote on a separate endnote page.
     const IDocumentSettingAccess& rSettings = GetDoc().getIDocumentSettingAccess();
     bool bContinuousEndnotes = rSettings.get(DocumentSettingId::CONTINUOUS_ENDNOTES);
-    const bool bEnd = pFootnote->GetFootnote().IsEndNote() && !bContinuousEndnotes;
+    const bool bEnd = pFootnote->GetFootnote().IsEndNote();
 
     // We want to store this value, because it is needed as a fallback
     // in GetFootnoteLine(), if there is no paragraph information available
@@ -615,11 +615,15 @@ void SwTextFrame::ConnectFootnote( SwTextFootnote *pFootnote, const SwTwips nDea
 
     if( bDocEnd )
     {
-        if( pSect && pSrcFrame )
+        if ((pSect || bContinuousEndnotes) && pSrcFrame)
         {
             SwFootnoteFrame *pFootnoteFrame = SwFootnoteBossFrame::FindFootnote( pSrcFrame, pFootnote );
-            if( pFootnoteFrame && pFootnoteFrame->IsInSct() )
+            if (pFootnoteFrame && (pFootnoteFrame->IsInSct() || bContinuousEndnotes))
             {
+                // We either have a foot/endnote that goes to the end of the section or are in Word
+                // compatibility mode where endnotes go to the end of the document.  Handle both
+                // cases by removing the footnote here, then later appending them to the correct
+                // last page of the document or section.
                 pBoss->RemoveFootnote( pSrcFrame, pFootnote );
                 pSrcFrame = nullptr;
             }


More information about the Libreoffice-commits mailing list