summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-03-27 12:03:06 +0100
committerMichael Stahl <michael.stahl@allotropia.de>2022-05-13 14:14:27 +0200
commitd5ff98e5d135a81a54c517dd9300dbb93ad7a1e4 (patch)
treeeb37e713b76c30a6a89ca52f2de8b3c8b105b27c
parent90557911cf1b736075baa803d5a682aaa0a001bc (diff)
forcepoint#92 fix crash on layout of specific doc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132142 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132148 Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> (cherry picked from commit 0d0cee5e48ca523f11540e9ae0ff022692fd9dca) (cherry picked from commit 86108b6ddabcbd0e649a6bc4d182a82a92025b69) Change-Id: Id40d25d05d10d641d071cddd2e1c84594ac777a6
-rw-r--r--sw/inc/deletelistener.hxx92
-rw-r--r--sw/qa/extras/layout/data/forcepoint92.docbin0 -> 29200 bytes
-rw-r--r--sw/qa/extras/layout/layout.cxx5
-rw-r--r--sw/source/core/layout/tabfrm.cxx9
4 files changed, 105 insertions, 1 deletions
diff --git a/sw/inc/deletelistener.hxx b/sw/inc/deletelistener.hxx
new file mode 100644
index 000000000000..bfdc0926d3b6
--- /dev/null
+++ b/sw/inc/deletelistener.hxx
@@ -0,0 +1,92 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#pragma once
+
+#include <svl/listener.hxx>
+#include <svl/lstner.hxx>
+#include "calbck.hxx"
+
+class SwDeleteListener final : public SwClient
+{
+private:
+ SwModify* m_pModify;
+
+ virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) override
+ {
+ if (auto pLegacy = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
+ {
+ if (pLegacy->m_pOld && pLegacy->m_pOld->Which() == RES_OBJECTDYING)
+ {
+ m_pModify->Remove(this);
+ m_pModify = nullptr;
+ }
+ }
+ }
+
+public:
+ SwDeleteListener(SwModify& rModify)
+ : m_pModify(&rModify)
+ {
+ m_pModify->Add(this);
+ }
+
+ bool WasDeleted() const { return !m_pModify; }
+
+ virtual ~SwDeleteListener() override
+ {
+ if (!m_pModify)
+ return;
+ m_pModify->Remove(this);
+ }
+};
+
+class SvtDeleteListener final : public SvtListener
+{
+private:
+ bool bObjectDeleted;
+
+public:
+ explicit SvtDeleteListener(SvtBroadcaster& rNotifier)
+ : bObjectDeleted(false)
+ {
+ StartListening(rNotifier);
+ }
+
+ virtual void Notify(const SfxHint& rHint) override
+ {
+ if (rHint.GetId() == SfxHintId::Dying)
+ bObjectDeleted = true;
+ }
+
+ bool WasDeleted() const { return bObjectDeleted; }
+};
+
+class SfxDeleteListener final : public SfxListener
+{
+private:
+ bool bObjectDeleted;
+
+public:
+ explicit SfxDeleteListener(SfxBroadcaster& rNotifier)
+ : bObjectDeleted(false)
+ {
+ StartListening(rNotifier);
+ }
+
+ virtual void Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint) override
+ {
+ if (rHint.GetId() == SfxHintId::Dying)
+ bObjectDeleted = true;
+ }
+
+ bool WasDeleted() const { return bObjectDeleted; }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sw/qa/extras/layout/data/forcepoint92.doc b/sw/qa/extras/layout/data/forcepoint92.doc
new file mode 100644
index 000000000000..49c4a7f11dfe
--- /dev/null
+++ b/sw/qa/extras/layout/data/forcepoint92.doc
Binary files differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 2576203d0703..5e9e2b2d950b 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -34,6 +34,7 @@ public:
void testForcepoint76();
void testN4LA0OHZ();
void testUXTSOREL();
+ void testForcepoint92();
void testTdf118058();
void testTdf117188();
void testTdf119875();
@@ -56,6 +57,7 @@ public:
CPPUNIT_TEST(testForcepoint76);
CPPUNIT_TEST(testN4LA0OHZ);
//FIXME this asserts CPPUNIT_TEST(testUXTSOREL);
+ CPPUNIT_TEST(testForcepoint92);
CPPUNIT_TEST(testTdf118058);
CPPUNIT_TEST(testTdf117188);
CPPUNIT_TEST(testTdf119875);
@@ -264,6 +266,9 @@ void SwLayoutWriter::testN4LA0OHZ() { createDoc("LIBREOFFICE-N4LA0OHZ.rtf"); }
void SwLayoutWriter::testUXTSOREL() { createDoc("LIBREOFFICE-UXTSOREL.rtf"); }
#endif
+//just care it doesn't crash/assert
+void SwLayoutWriter::testForcepoint92() { createDoc("forcepoint92.doc"); }
+
void SwLayoutWriter::testTdf118058()
{
SwDoc* pDoc = createDoc("tdf118058.fodt");
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 05d189103d2f..f3048bcdeb2f 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -23,6 +23,7 @@
#include <viewimp.hxx>
#include <fesh.hxx>
#include <swtable.hxx>
+#include <deletelistener.hxx>
#include <dflyobj.hxx>
#include <anchoreddrawobject.hxx>
#include <fmtanchr.hxx>
@@ -58,6 +59,7 @@
#include <DocumentSettingManager.hxx>
#include <docary.hxx>
#include <o3tl/make_unique.hxx>
+#include <optional>
using namespace ::com::sun::star;
@@ -2031,13 +2033,18 @@ void SwTabFrame::MakeAll(vcl::RenderContext* pRenderContext)
}
SwFootnoteBossFrame *pOldBoss = bFootnotesInDoc ? FindFootnoteBossFrame( true ) : nullptr;
bool bReformat;
+ std::optional<SfxDeleteListener> oDeleteListener;
+ if (pOldBoss)
+ oDeleteListener.emplace(*pOldBoss);
SwFrameDeleteGuard g(this);
if ( MoveBwd( bReformat ) )
{
+ SAL_WARN_IF(oDeleteListener && oDeleteListener->WasDeleted(), "sw.layout", "SwFootnoteBossFrame unexpectedly deleted");
+
aRectFnSet.Refresh(this);
bMovedBwd = true;
aNotify.SetLowersComplete( false );
- if ( bFootnotesInDoc )
+ if (bFootnotesInDoc && !oDeleteListener->WasDeleted())
MoveLowerFootnotes( nullptr, pOldBoss, nullptr, true );
if ( bReformat || bKeep )
{