From 1c8efde4daea648204e3ba19f8edc01ef3e548bd Mon Sep 17 00:00:00 2001
From: Michael Stahl <mstahl@redhat.com>
Date: Wed, 14 Feb 2018 12:57:49 +0100
Subject: tdf#83260 sw: call CompressRedlines() in ODF import

It's possible that an ODF document contains redlines that will be
deduplicated by CompressRedlines().

If that happens during some editing operation, then a SwRedline
will be deleted and the nodes array becomes smaller by at least 3
nodes; any Undo actions that were created prior to the operation
that called CompressRedlines() will store invalid node indexes now
and Undo will crash.

So presumably it's a precondition of editing operations
that CompressRedlines() is a no-op.

Interestingly CompressRedlines() is also called from
SwEditShell::Undo()/Redo().

Ensure it's a no-op later by calling CompressRedlines() immediately
after load.

(Hopefully this should also work for the Insert File case.)

Add a test too.

Change-Id: Iec8135cc60260ed5cfff05a196b5c92cc03265f9
Reviewed-on: https://gerrit.libreoffice.org/49721
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
---
 editeng/source/misc/svxacorr.cxx | 4 ++++
 1 file changed, 4 insertions(+)

(limited to 'editeng')

diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx
index 1119879f178c..302c941b06b7 100644
--- a/editeng/source/misc/svxacorr.cxx
+++ b/editeng/source/misc/svxacorr.cxx
@@ -1228,6 +1228,7 @@ OUString SvxAutoCorrect::GetQuote( SvxAutoCorrDoc const & rDoc, sal_Int32 nInsPo
     return sRet;
 }
 
+// WARNING: rText may become invalid, see comment below
 void SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const OUString& rTxt,
                                     sal_Int32 nInsPos, sal_Unicode cChar,
                                     bool bInsert, bool& io_bNbspRunNext, vcl::Window const * pFrameWin )
@@ -1338,6 +1339,9 @@ void SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const OUString& rTxt,
 
         if( IsAutoCorrFlag( Autocorrect ) )
         {
+            // WARNING ATTENTION: rTxt is an alias of the text node's OUString
+            // and becomes INVALID if ChgAutoCorrWord returns true!
+            // => use aPara/pPara to create a valid copy of the string!
             OUString aPara;
             OUString* pPara = IsAutoCorrFlag(CapitalStartSentence) ? &aPara : nullptr;
 
-- 
cgit