summaryrefslogtreecommitdiffstats
path: root/sw/source
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2022-08-15 20:47:13 +0200
committerMichael Stahl <michael.stahl@allotropia.de>2022-09-23 14:27:40 +0200
commit47f896a30da723d9e0043c1772b207d949ce8b6e (patch)
tree3057ea5efc0eaa268ea3e1505c60af29346dc6c7 /sw/source
parentforcepoint#110 set PaMs to somewhere safe to park (diff)
downloadcore-47f896a30da723d9e0043c1772b207d949ce8b6e.tar.gz
core-47f896a30da723d9e0043c1772b207d949ce8b6e.zip
forcepoint#108 sw: prevent creating SwRangeRedline anchored in itself
the SwRangeRedline in frame #8 triggers deleting itself at frame #0 which repeats the DeleteSection attempt which is already in progress #0 SwRangeRedline::~SwRangeRedline() (this=0x5335300) at sw/source/core/doc/docredln.cxx:1168 #1 0x00007fffc9b91aab in SwRedlineTable::DeleteAndDestroy(unsigned long) (this=0x4f388f8, nP=0) at sw/source/core/doc/docredln.cxx:669 #2 0x00007fffc9c8454a in sw::DocumentRedlineManager::DeleteRedline(SwPaM const&, bool, RedlineType) (this=0x4f388e0, rRange=SwPaM = {...}, bSaveInUndo=true, nDelType=RedlineType::Any) at sw/source/core/doc/DocumentRedlineManager.cxx:2578 #3 0x00007fffc9c84a2f in sw::DocumentRedlineManager::DeleteRedline(SwStartNode const&, bool, RedlineType) (this=0x4f388e0, rNode=..., bSaveInUndo=true, nDelType=RedlineType::Any) at sw/source/core/doc/DocumentRedlineManager.cxx:2676 #4 0x00007fffc9c1c57f in sw::DocumentContentOperationsManager::DeleteSection(SwNode*) (this=0x4f3b460, pNode=0x5331780) at sw/source/core/doc/DocumentContentOperationsManager.cxx:2092 #5 0x00007fffc9cbfea7 in sw::DocumentLayoutManager::DelLayoutFormat(SwFrameFormat*) (this=0x4edad40, pFormat=0x53318b0) at sw/source/core/doc/DocumentLayoutManager.cxx:285 #6 0x00007fffc9a9abd2 in DelFlyInRange(SwNode&, SwNode&, SwContentIndex const*, SwContentIndex const*) (rMkNd=..., rPtNd=..., pMkIdx=0x0, pPtIdx=0x0) at sw/source/core/doc/docedt.cxx:254 #7 0x00007fffc9c1c53d in sw::DocumentContentOperationsManager::DeleteSection(SwNode*) (this=0x4f3b460, pNode=0x532a1f0) at sw/source/core/doc/DocumentContentOperationsManager.cxx:2091 #8 0x00007fffc9b965f7 in SwRangeRedline::MoveFromSection(unsigned long) (this=0x5335300, nMyPos=0) at sw/source/core/doc/docredln.cxx:1834 #9 0x00007fffc9b951f8 in SwRangeRedline::Show(unsigned short, unsigned long, bool) (this=0x5335300, nLoop=1, nMyPos=0, bForced=false) at sw/source/core/doc/docredln.cxx:1277 #10 0x00007fffc9c7d64b in sw::DocumentRedlineManager::SetRedlineFlags(RedlineFlags) (this=0x4f388e0, eMode=RedlineFlags::ShowMask) at sw/source/core/doc/DocumentRedlineManager.cxx:1149 #11 0x00007fffcb129668 in SwXTextDocument::setPropertyValue(rtl::OUString const&, com::sun::star::uno::Any const&) (this=0x4f52730, rPropertyName="ShowChanges", aValue=uno::Any("boolean": 1 '\001')) at sw/source/uibase/uno/unotxdoc.cxx:1795 #12 0x00007fffcab7ce8d in XMLRedlineImportHelper::~XMLRedlineImportHelper() (this=0x52792f0) at sw/source/filter/xml/XMLRedlineImportHelper.cxx:341 #13 0x00007fffcac2366d in SwXMLTextImportHelper::~SwXMLTextImportHelper() (this=0x527cae0) at sw/source/filter/xml/xmltexti.cxx:157 #14 0x00007fffcac236a9 in SwXMLTextImportHelper::~SwXMLTextImportHelper() (this=0x527cae0) at sw/source/filter/xml/xmltexti.cxx:152 #15 0x00007fffea9d5ee2 in salhelper::SimpleReferenceObject::release() (this=0x527cae0) at include/salhelper/simplereferenceobject.hxx:76 #16 0x00007fffeabc2619 in rtl::Reference<XMLTextImportHelper>::clear() (this=0x525cd60) at include/rtl/ref.hxx:196 #17 0x00007fffeabb07e0 in SvXMLImport::cleanup() (this=0x525ccd0) at xmloff/source/core/xmlimp.cxx:458 #18 0x00007fffeabb08bf in SvXMLImport::~SvXMLImport() (this=0x525ccd0) at xmloff/source/core/xmlimp.cxx:464 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138191 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit a8b3953531035bf93306ed90142c4172cc32ac43) forcepoint#108 sw: tweak a bit * the fly-at-fly case didn't work, iteration also skips it * delete the bad redline section in the nodes array Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138434 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> (cherry picked from commit 477e489e71b4a96ff10d9f2d2b802d91dec3e319) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138289 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de> (cherry picked from commit 2d16f0639b74bcc9328fbb77f774cf9141d1675b) Change-Id: I640874df3fd10af935cf05df707d45bea2c9fd6e
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/filter/xml/XMLRedlineImportHelper.cxx82
1 files changed, 82 insertions, 0 deletions
diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
index 250a31688151..15e6651661b3 100644
--- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx
+++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
@@ -31,6 +31,10 @@
#include <IDocumentStylePoolAccess.hxx>
#include <tools/datetime.hxx>
#include <poolfmt.hxx>
+#include <fmtanchr.hxx>
+#include <ftnidx.hxx>
+#include <txtftn.hxx>
+#include <ndtxt.hxx>
#include <unoredline.hxx>
#include <o3tl/any.hxx>
#include <xmloff/xmltoken.hxx>
@@ -562,6 +566,73 @@ inline bool XMLRedlineImportHelper::IsReady(RedlineInfo* pRedline)
!pRedline->bNeedsAdjustment );
}
+/// recursively check if rPos or its anchor (if in fly or footnote) is in redline section
+static auto RecursiveContains(SwStartNode const& rRedlineSection, SwNode const& rPos) -> bool
+{
+ if (rRedlineSection.GetIndex() <= rPos.GetIndex()
+ && rPos.GetIndex() <= rRedlineSection.EndOfSectionIndex())
+ {
+ return true;
+ }
+ // loop to iterate "up" in the node tree and find an anchored XText
+ for (SwStartNode const* pStartNode = rPos.StartOfSectionNode();
+ pStartNode != nullptr && pStartNode->GetIndex() != 0;
+ pStartNode = pStartNode->StartOfSectionNode())
+ {
+ switch (pStartNode->GetStartNodeType())
+ {
+ case SwNormalStartNode:
+ case SwTableBoxStartNode:
+ continue;
+ break;
+ case SwFlyStartNode:
+ {
+ SwFrameFormat const*const pFormat(pStartNode->GetFlyFormat());
+ assert(pFormat);
+ SwFormatAnchor const& rAnchor(pFormat->GetAnchor());
+ if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PAGE)
+ {
+ return false;
+ }
+ else if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_FLY)
+ { // anchor is on a start node, avoid skipping it:
+ pStartNode = rAnchor.GetContentAnchor()->nNode.GetNode().GetStartNode();
+ assert(pStartNode);
+ // pass the next node to recursive call - it will call
+ // call StartOfSectionNode on it and go back to pStartNode
+ SwNodeIndex const next(*pStartNode, +1);
+ return RecursiveContains(rRedlineSection, next.GetNode());
+ }
+ else
+ {
+ return RecursiveContains(rRedlineSection, rAnchor.GetContentAnchor()->nNode.GetNode());
+ }
+ }
+ break;
+ case SwFootnoteStartNode:
+ { // sigh ... need to search
+ for (SwTextFootnote const*const pFootnote : rRedlineSection.GetDoc()->GetFootnoteIdxs())
+ {
+ if (pStartNode == pFootnote->GetStartNode()->GetNode().GetStartNode())
+ {
+ return RecursiveContains(rRedlineSection, pFootnote->GetTextNode());
+ }
+ }
+ assert(false);
+ }
+ break;
+ case SwHeaderStartNode:
+ case SwFooterStartNode:
+ return false; // headers aren't anchored
+ break;
+ default:
+ assert(false);
+ break;
+ }
+ }
+ return false;
+}
+
void XMLRedlineImportHelper::InsertIntoDocument(RedlineInfo* pRedlineInfo)
{
OSL_ENSURE(nullptr != pRedlineInfo, "need redline info");
@@ -631,6 +702,17 @@ void XMLRedlineImportHelper::InsertIntoDocument(RedlineInfo* pRedlineInfo)
}
}
}
+ else if (pRedlineInfo->pContentIndex != nullptr
+ // should be enough to check 1 position of aPaM bc CheckNodesRange() above
+ && RecursiveContains(*pRedlineInfo->pContentIndex->GetNode().GetStartNode(), aPaM.GetPoint()->nNode.GetNode()))
+ {
+ SAL_WARN("sw.xml", "Recursive change tracking, removing");
+ // reuse aPaM to remove it from nodes that will be deleted
+ *aPaM.GetPoint() = SwPosition(pRedlineInfo->pContentIndex->GetNode());
+ aPaM.SetMark();
+ *aPaM.GetMark() = SwPosition(*pRedlineInfo->pContentIndex->GetNode().EndOfSectionNode());
+ pDoc->getIDocumentContentOperations().DeleteRange(aPaM);
+ }
else
{
// regular file loading: insert redline