From 087a6b0cf34ab64801dba5aa7ff3d7ea53c2272b Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Mon, 11 Nov 2019 18:23:15 +0100 Subject: [PATCH] toolkit: UnoEditControl::insertText() assert on invalid index ... in replaceAt(): if the selection that is passed in is invalid, throw an exception. This obviously isn't thread-safe but naively adding a GetMutex() guard quickly deadlocks against SolarMutex; why does it use its own mutex? Reproduces when installing APSO 1.2.5 and starting the Python REPL. Change-Id: I4fb16ab820641f1a031537b0c4d6f8664d67dc0c Reviewed-on: https://gerrit.libreoffice.org/82460 Tested-by: Jenkins Reviewed-by: Michael Stahl --- toolkit/source/controls/unocontrols.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/toolkit/source/controls/unocontrols.cxx b/toolkit/source/controls/unocontrols.cxx index e2ebbf77ed41..cbb04926bd95 100644 --- a/toolkit/source/controls/unocontrols.cxx +++ b/toolkit/source/controls/unocontrols.cxx @@ -327,6 +327,12 @@ void UnoEditControl::insertText( const awt::Selection& rSel, const OUString& rNe awt::Selection aSelection( rSel ); lcl_normalize( aSelection ); + OUString aOldText = getText(); + if (aSelection.Min < 0 || aOldText.getLength() < aSelection.Max) + { + throw lang::IllegalArgumentException(); + } + // preserve the selection resp. cursor position awt::Selection aNewSelection( getSelection() ); #ifdef ALSO_PRESERVE_COMPLETE_SELECTION @@ -341,7 +347,6 @@ void UnoEditControl::insertText( const awt::Selection& rSel, const OUString& rNe aNewSelection.Min = aNewSelection.Max; #endif - OUString aOldText = getText(); OUString aNewText = aOldText.replaceAt( aSelection.Min, aSelection.Max - aSelection.Min, rNewText ); setText( aNewText );