From b1dc1c740e37639bb309f4aa6a1c2567f99083fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Wed, 29 Jul 2020 13:51:14 +0100 Subject: [PATCH] ofz#24404 row insert attempt in table with same table already in the row MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I0f52de029600b182e479af3bdf56da7ea2c2ef01 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99691 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- .../inc/xfilter/xfcontentcontainer.hxx | 2 ++ .../filter/xfilter/xfcontentcontainer.cxx | 18 ++++++++++++++++++ lotuswordpro/source/filter/xfilter/xftable.cxx | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lotuswordpro/inc/xfilter/xfcontentcontainer.hxx b/lotuswordpro/inc/xfilter/xfcontentcontainer.hxx index f3a843f1481f..e8ad3347ebab 100644 --- a/lotuswordpro/inc/xfilter/xfcontentcontainer.hxx +++ b/lotuswordpro/inc/xfilter/xfcontentcontainer.hxx @@ -125,6 +125,8 @@ public: */ virtual void ToXml(IXFStream *pStrm) override; + bool HierarchyContains(const XFContent *pContent) const; + private: std::vector< rtl::Reference > m_aContents; }; diff --git a/lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx b/lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx index b64ad72721a4..14aaea9515df 100644 --- a/lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx +++ b/lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx @@ -80,6 +80,24 @@ void XFContentContainer::Add(const OUString& text) Add(xTC.get()); } +bool XFContentContainer::HierarchyContains(const XFContent *pContent) const +{ + if (pContent == this) + return true; + + for (int i = 0, nCount = GetCount(); i < nCount; i++) + { + rtl::Reference xContent = GetContent(i); + if (xContent.get() == pContent) + return true; + const XFContentContainer *pChildCont = dynamic_cast(xContent.get()); + if (pChildCont && pChildCont->HierarchyContains(pContent)) + return true; + } + + return false; +} + int XFContentContainer::GetCount() const { return m_aContents.size(); diff --git a/lotuswordpro/source/filter/xfilter/xftable.cxx b/lotuswordpro/source/filter/xfilter/xftable.cxx index 07da1a57d4fc..6acb1b21a35f 100644 --- a/lotuswordpro/source/filter/xfilter/xftable.cxx +++ b/lotuswordpro/source/filter/xfilter/xftable.cxx @@ -88,7 +88,7 @@ void XFTable::AddRow(rtl::Reference const & rRow) for (sal_Int32 i = 0; i < rRow->GetCellCount(); ++i) { XFCell* pFirstCell = rRow->GetCell(i + 1); //starts at 1, not 0 - if (pFirstCell->GetSubTable() == this) + if (pFirstCell->GetSubTable() == this || pFirstCell->HierarchyContains(this)) throw std::runtime_error("table is a subtable of itself"); }