summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2023-05-24 15:40:35 +0200
committerCaolán McNamara <caolan.mcnamara@collabora.com>2023-05-26 13:30:16 +0200
commit5f90963149509364d34fae5ecc759989620ee906 (patch)
treea53b2f38a0aa588d82bcac63709cf9a2761d286e
parenttdf#155350 Do AutoCorrect of Input Method text (diff)
downloadcore-5f90963149509364d34fae5ecc759989620ee906.tar.gz
core-5f90963149509364d34fae5ecc759989620ee906.zip
sw: fix wrong downcast in UndoManager::IsViewUndoActionIndependent()
In case a user types in one view, an other user types in an other view, finally the first user deletes, then getting the undo state resulted in a memory corruption. This went wrong in commit 2875c65946e59f5dd7968155463bf00bd71d440b (sw, out of order undo: allow a subset of a non-empty redo list, 2021-11-11), the intention was to check if we have a redo item and it has the expected type, but we checked the type of an earlier undo action that belongs to the view. Fix the problem by checking the type of the correct undo action, this was probably a copy&paste error of mine. Resolves <https://github.com/CollaboraOnline/online/issues/6412>. (cherry picked from commit f0a9d4d4eea6562e98fd92a2797d16504e1d4db5) Change-Id: I6cb2a081067695a045d86b4ef427cc5a76c0f9c4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152269 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
-rw-r--r--sw/qa/extras/tiledrendering/tiledrendering.cxx42
-rw-r--r--sw/source/core/undo/docundo.cxx2
2 files changed, 43 insertions, 1 deletions
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 3330e419dc8b..cc1dbd4947c2 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -1322,6 +1322,48 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testUndoReorderingRedo)
SfxViewShell::Current()->setLibreOfficeKitViewCallback(nullptr);
}
+CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testUndoReorderingRedo2)
+{
+ // Create two views.
+ SwXTextDocument* pXTextDocument = createDoc();
+ SwWrtShell* pWrtShell1 = pXTextDocument->GetDocShell()->GetWrtShell();
+ int nView1 = SfxLokHelper::getView();
+ int nView2 = SfxLokHelper::createView();
+ pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
+ SwWrtShell* pWrtShell2 = pXTextDocument->GetDocShell()->GetWrtShell();
+
+ // Type in the first view.
+ SfxLokHelper::setView(nView1);
+ pWrtShell1->SttEndDoc(/*bStt=*/true);
+ pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'f', 0);
+ pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'f', 0);
+ Scheduler::ProcessEventsToIdle();
+
+ // Type to the same paragraph in the second view.
+ SfxLokHelper::setView(nView2);
+ pWrtShell2->SttEndDoc(/*bStt=*/true);
+ pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 's', 0);
+ pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 's', 0);
+ Scheduler::ProcessEventsToIdle();
+
+ // Delete in the first view and undo.
+ SfxLokHelper::setView(nView1);
+ pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::BACKSPACE);
+ pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::BACKSPACE);
+ Scheduler::ProcessEventsToIdle();
+ dispatchCommand(mxComponent, ".uno:Undo", {});
+ Scheduler::ProcessEventsToIdle();
+
+ // Query the undo state, now that a "delete" is on the redo stack and an "insert" belongs to the
+ // view on the undo stack, so the types are different.
+ SwUndoId nUndoId(SwUndoId::EMPTY);
+ // Without the accompanying fix in place, this test would have failed with:
+ // runtime error: downcast which does not point to an object of type 'const SwUndoInsert'
+ // note: object is of type 'SwUndoDelete'
+ // in an UBSan build.
+ pWrtShell1->GetLastUndoInfo(nullptr, &nUndoId, &pWrtShell1->GetView());
+}
+
CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testUndoReorderingMulti)
{
// Create two views and a document of 2 paragraphs.
diff --git a/sw/source/core/undo/docundo.cxx b/sw/source/core/undo/docundo.cxx
index 07998e9404ef..ccff1b663cf3 100644
--- a/sw/source/core/undo/docundo.cxx
+++ b/sw/source/core/undo/docundo.cxx
@@ -415,7 +415,7 @@ bool UndoManager::IsViewUndoActionIndependent(const SwView* pView, sal_uInt16& r
for (size_t i = 0; i < GetRedoActionCount(); ++i)
{
auto pRedoAction = dynamic_cast<const SwUndo*>(GetRedoAction(i));
- if (!pRedoAction || pViewSwAction->GetId() != SwUndoId::TYPING)
+ if (!pRedoAction || pRedoAction->GetId() != SwUndoId::TYPING)
{
return false;
}