[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sd/inc sd/source

2021-06-15 Thread Tomaž Vajngerl (via logerrit)
 sd/inc/Outliner.hxx|3 +
 sd/source/ui/view/Outliner.cxx |   63 +
 2 files changed, 36 insertions(+), 30 deletions(-)

New commits:
commit 0286b989b86fc4934e77ef1c1596fc0355b10748
Author: Tomaž Vajngerl 
AuthorDate: Wed Jun 9 14:58:28 2021 +0900
Commit: Miklos Vajna 
CommitDate: Tue Jun 15 09:52:19 2021 +0200

sd: ubsan - fix heap-use-after-free in SdOutliner

OutlinerView can change (old one deleted and new one create)
so we can't store it in a local vairable and need to always
fetch it.

UBSAN Error log:
==21484==ERROR: AddressSanitizer: heap-use-after-free on address 
0x606000af7d28 at pc 0x2ab7c5979405 bp 0x7ffcd1a3d1a0 sp 0x7ffcd1a3d198
  READ of size 8 at 0x606000af7d28 thread T0
  -0 0x2ab7c5979404 in std::__uniq_ptr_impl >::_M_ptr() const 
/home/tdf/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/unique_ptr.h:147:42
  -1 0x2ab7c59792ea in std::unique_ptr >::get() const 
/home/tdf/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/unique_ptr.h:337:21
  -2 0x2ab7c59791d9 in std::unique_ptr >::operator*() const 
/home/tdf/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/unique_ptr.h:322:2
  -3 0x2ab7c59725da in OutlinerView::GetEditView() const 
/include/editeng/outliner.hxx:209:46
  -4 0x2ab7c70e36bb in 
SdOutliner::SearchAndReplaceOnce(std::__debug::vector >*) /sd/source/ui/view/Outliner.cxx:903:21
  -5 0x2ab7c70dcb32 in SdOutliner::SearchAndReplaceAll() 
/sd/source/ui/view/Outliner.cxx:622:29
  -6 0x2ab7c70da81b in SdOutliner::StartSearchAndReplace(SvxSearchItem 
const*) /sd/source/ui/view/Outliner.cxx:478:28
  -7 0x2ab7c61e4fc5 in sd::FuSearch::SearchAndReplace(SvxSearchItem 
const*) /sd/source/ui/func/fusearch.cxx:128:44
  -8 0x2ab7c5c61fc5 in sd::DrawDocShell::Execute(SfxRequest&) 
/sd/source/ui/docshell/docshel3.cxx:228:36
  -9 0x2ab7c5cac074 in SfxStubDrawDocShellExecute(SfxShell*, 
SfxRequest&) /workdir/SdiTarget/sd/sdi/sdslots.hxx:18384:1
  -10 0x2ab7cd885d8f in SfxDispatcher::Call_Impl(SfxShell&, SfxSlot 
const&, SfxRequest&, bool) /sfx2/source/control/dispatch.cxx:253:9
  -11 0x2ab7cd89bd8f in SfxDispatcher::Execute_(SfxShell&, SfxSlot 
const&, SfxRequest&, SfxCallMode) /sfx2/source/control/dispatch.cxx:753:9
  -12 0x2ab7cd89ccd6 in SfxDispatcher::Execute(unsigned short, 
SfxCallMode, SfxItemSet const*, SfxItemSet const*, unsigned short) 
/sfx2/source/control/dispatch.cxx:811:9
  -13 0x2ab7cdd11d76 in 
SfxDispatchController_Impl::dispatch(com::sun::star::util::URL const&, 
com::sun::star::uno::Sequence const&, 
com::sun::star::uno::Reference 
const&) /sfx2/source/control/unoctitm.cxx:738:46
  -14 0x2ab7cdd15135 in 
SfxOfficeDispatch::dispatchWithNotification(com::sun::star::util::URL const&, 
com::sun::star::uno::Sequence const&, 
com::sun::star::uno::Reference 
const&) /sfx2/source/control/unoctitm.cxx:243:16
  -15 0x2ab7f54b25d7 in 
framework::DispatchHelper::executeDispatch(com::sun::star::uno::Reference
 const&, com::sun::star::util::URL const&, bool, 
com::sun::star::uno::Sequence const&) 
/framework/source/services/dispatchhelper.cxx:159:30
  -16 0x2ab7f54b1531 in 
framework::DispatchHelper::executeDispatch(com::sun::star::uno::Reference
 const&, rtl::OUString const&, rtl::OUString const&, int, 
com::sun::star::uno::Sequence const&) 
/framework/source/services/dispatchhelper.cxx:117:16
  -17 0x2ab7f54b2d17 in non-virtual thunk to 
framework::DispatchHelper::executeDispatch(com::sun::star::uno::Reference
 const&, rtl::OUString const&, rtl::OUString const&, int, 
com::sun::star::uno::Sequence const&) 
/framework/source/services/dispatchhelper.cxx
  -18 0x2ab7e63c546f in 
unotest::MacrosTest::dispatchCommand(com::sun::star::uno::Reference
 const&, rtl::OUString const&, 
com::sun::star::uno::Sequence const&) 
/unotest/source/cpp/macros_test.cxx:85:22
  -19 0x2ab7b1a9ac2d in testSearchAllInDocumentAndNotes::TestBody() 
/sd/qa/unit/uiimpress.cxx:715:5
  -20 0x2ab7b1b43f84 in void std::__invoke_impl(std::__invoke_memfun_deref, void 
(testSearchAllInDocumentAndNotes::*&)(), testSearchAllInDocumentAndNotes*&) 
/home/tdf/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/invoke.h:73:14
  -21 0x2ab7b1b43b5e in std::__invoke_result::type std::__invoke(void 
(testSearchAllInDocumentAndNotes::*&)(), testSearchAllInDocumentAndNotes*&) 
/home/tdf/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/invoke.h:95:14
  -22 0x2ab7b1b439b2 in void std::_Bind::__call(std::tuple<>&&, 
std::_Index_tuple<0ul>) 

[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sd/inc sd/source

2020-08-19 Thread Tomaž Vajngerl (via logerrit)
 sd/inc/VectorGraphicSearchContext.hxx |   35 
 sd/source/ui/inc/View.hxx |6 +++
 sd/source/ui/view/Outliner.cxx|   59 ++
 3 files changed, 66 insertions(+), 34 deletions(-)

New commits:
commit b34e80b3a8d0b9032556d82bc2619e450802dc8c
Author: Tomaž Vajngerl 
AuthorDate: Sun Aug 16 12:06:30 2020 +0200
Commit: Tomaž Vajngerl 
CommitDate: Wed Aug 19 10:36:40 2020 +0200

move vector graphic search to View, so it works in multiple views

VectorGraphicSearch was instantiated for the Outline, which is
the same for every view. The problem with this is that when we
have multiple views, the search would interfere with each other,
which is especially distracting in online when multiple users
connect to the same document and try searching.
This adds VectorGraphicSearchContext class, that is added to the
View, which makes the search view dependent and multiple instances
of VectorGraphicSearch are created, each one for its own view.

Change-Id: Ia0f34647b30b35f4ddb84d33353990d635756905
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100837
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 
(cherry picked from commit 74e2f2178fd8a0ad29c5dbcefb22a9778a75ae82)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100884
Tested-by: Jenkins CollaboraOffice 

diff --git a/sd/inc/VectorGraphicSearchContext.hxx 
b/sd/inc/VectorGraphicSearchContext.hxx
new file mode 100644
index ..e6f978ca273c
--- /dev/null
+++ b/sd/inc/VectorGraphicSearchContext.hxx
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+#include 
+
+namespace sd
+{
+struct VectorGraphicSearchContext
+{
+bool mbCurrentIsVectorGraphic;
+std::unique_ptr mpVectorGraphicSearch;
+
+VectorGraphicSearchContext()
+: mbCurrentIsVectorGraphic(false)
+{
+}
+
+void reset()
+{
+mbCurrentIsVectorGraphic = false;
+mpVectorGraphicSearch.reset();
+}
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/inc/View.hxx b/sd/source/ui/inc/View.hxx
index 5aba1fb326d9..d7da6fc2df12 100644
--- a/sd/source/ui/inc/View.hxx
+++ b/sd/source/ui/inc/View.hxx
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "smarttag.hxx"
 
@@ -217,6 +218,8 @@ public:
 void SetAuthor(const OUString& rAuthor) { m_sAuthor = rAuthor; }
 const OUString& GetAuthor() const { return m_sAuthor; }
 
+VectorGraphicSearchContext& getVectorGraphicSearchContext() { return 
aVectorGraphicSearchContext; }
+
 protected:
 DECL_LINK( OnParagraphInsertedHdl, ::Outliner::ParagraphHdlParam, void );
 DECL_LINK( OnParagraphRemovingHdl, ::Outliner::ParagraphHdlParam, void );
@@ -250,6 +253,9 @@ protected:
 private:
 ::std::unique_ptr mpClipboard;
 OutlinerMasterViewFilter maMasterViewFilter;
+
+VectorGraphicSearchContext aVectorGraphicSearchContext;
+
 OUString m_sAuthor;
 };
 
diff --git a/sd/source/ui/view/Outliner.cxx b/sd/source/ui/view/Outliner.cxx
index 9b777d3a1dad..7f6a1853d753 100644
--- a/sd/source/ui/view/Outliner.cxx
+++ b/sd/source/ui/view/Outliner.cxx
@@ -21,7 +21,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -61,6 +60,7 @@
 #include 
 #include 
 #include 
+#include 
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -99,11 +99,6 @@ public:
 */
 void ReleaseOutlinerView();
 
-/** Search in vector graphic
- */
-bool mbCurrentIsVectorGraphic;
-std::unique_ptr mpVectorGraphicSearch;
-
 private:
 /** Flag that specifies whether we own the outline view pointed to by
 mpOutlineView and thus have to
@@ -729,9 +724,10 @@ void 
SdOutliner::sendLOKSearchResultCallback(std::shared_ptr & pV
  std::vector* 
pSelections)
 {
 std::vector<::tools::Rectangle> aLogicRects;
-if (mpImpl->mbCurrentIsVectorGraphic)
+auto& rVectorGraphicSearchContext = 
pViewShell->GetView()->getVectorGraphicSearchContext();
+if (rVectorGraphicSearchContext.mbCurrentIsVectorGraphic)
 {
-basegfx::B2DRectangle aSelectionHMM = 
getPDFSelection(mpImpl->mpVectorGraphicSearch, mpObj);
+basegfx::B2DRectangle aSelectionHMM = 
getPDFSelection(rVectorGraphicSearchContext.mpVectorGraphicSearch, mpObj);
 
 tools::Rectangle aSelection(Point(aSelectionHMM.getMinX(), 
aSelectionHMM.getMinY()),
 Size(aSelectionHMM.getWidth(), 
aSelectionHMM.getHeight()));
@@ -787,7 +783,7 @@ void 

[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sd/inc sd/source

2020-06-09 Thread Tomaž Vajngerl (via logerrit)
 sd/inc/Outliner.hxx|7 ---
 sd/source/ui/view/Outliner.cxx |   20 +---
 2 files changed, 13 insertions(+), 14 deletions(-)

New commits:
commit 5bc2314a95199337e796de9be23650a71dff9294
Author: Tomaž Vajngerl 
AuthorDate: Wed May 27 14:13:02 2020 +0200
Commit: Tomaž Vajngerl 
CommitDate: Tue Jun 9 15:18:43 2020 +0200

sd: move IsValidTextObject into source as anon. function

IsValidTextObject is only used internally in Outline, so put it
inside the source file as an anonymous function and not as a
member function of Outliner.

Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95307
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 
(cherry picked from commit 14b55b3a8de070935489acd4f6f8be7b6a3d96a4)

Change-Id: I867dc4f465a694e61b6102b19f8e54ce623e2858
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95918
Tested-by: Tomaž Vajngerl 
Reviewed-by: Tomaž Vajngerl 

diff --git a/sd/inc/Outliner.hxx b/sd/inc/Outliner.hxx
index 39e2720f6a01..3e6514f16b80 100644
--- a/sd/inc/Outliner.hxx
+++ b/sd/inc/Outliner.hxx
@@ -411,13 +411,6 @@ private:
 */
 bool ShowWrapArroundDialog();
 
-/** Check whether the object pointed to by the iterator is a valid text
-object.
-@param aPosition
-The object for which to test whether it is a valid text object.
-*/
-static bool IsValidTextObject (const ::sd::outliner::IteratorPosition& 
rPosition);
-
 /** Put text of current text object into outliner so that the text can
 be searched/spell checked.
 */
diff --git a/sd/source/ui/view/Outliner.cxx b/sd/source/ui/view/Outliner.cxx
index 6e982f3d25f7..e77e60c5d305 100644
--- a/sd/source/ui/view/Outliner.cxx
+++ b/sd/source/ui/view/Outliner.cxx
@@ -1024,6 +1024,18 @@ void SdOutliner::RestoreStartPosition()
 }
 }
 
+namespace
+{
+
+bool lclIsValidTextObject(const sd::outliner::IteratorPosition& rPosition)
+{
+auto* pObject = dynamic_cast< SdrTextObj* >( rPosition.mxObject.get() );
+return (pObject != nullptr) && pObject->HasText() && ! 
pObject->IsEmptyPresObj();
+}
+
+} // end anonymous namespace
+
+
 /** The main purpose of this method is to iterate over all shape objects of
 the search area (current selection, current view, or whole document)
 until a text object has been found that contains at least one match or
@@ -1069,7 +1081,7 @@ void SdOutliner::ProvideNextTextObject()
 bool bForbiddenPage = comphelper::LibreOfficeKit::isActive() && 
(maCurrentPosition.mePageKind != PageKind::Standard || 
maCurrentPosition.meEditMode != EditMode::Page);
 
 // Switch to the current object only if it is a valid text object.
-if (!bForbiddenPage && IsValidTextObject(maCurrentPosition))
+if (!bForbiddenPage && lclIsValidTextObject(maCurrentPosition))
 {
 // Don't set yet in case of searching: the text object may not 
match.
 if (meMode != SEARCH)
@@ -1237,12 +1249,6 @@ bool SdOutliner::ShowWrapArroundDialog()
 return (nBoxResult == RET_YES);
 }
 
-bool SdOutliner::IsValidTextObject (const sd::outliner::IteratorPosition& 
rPosition)
-{
-SdrTextObj* pObject = dynamic_cast< SdrTextObj* >( 
rPosition.mxObject.get() );
-return (pObject != nullptr) && pObject->HasText() && ! 
pObject->IsEmptyPresObj();
-}
-
 void SdOutliner::PutTextIntoOutliner()
 {
 mpSearchSpellTextObj = dynamic_cast( mpObj );
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sd/inc sd/source

2020-06-09 Thread Tomaž Vajngerl (via logerrit)
 sd/inc/Outliner.hxx|4 +
 sd/source/ui/view/Outliner.cxx |  110 ++---
 2 files changed, 65 insertions(+), 49 deletions(-)

New commits:
commit 6eec4e40f6f8ea88d3136295d5485ee73ef7bf2c
Author: Tomaž Vajngerl 
AuthorDate: Wed May 27 14:07:10 2020 +0200
Commit: Tomaž Vajngerl 
CommitDate: Tue Jun 9 14:01:04 2020 +0200

sd: move LOK search result logic to it's own method

Change-Id: I67cbe4d3d63bffdab72c09b3a956f67806588348
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95306
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 
(cherry picked from commit e9dbdc9fc6ff943650e6e18986ed1cce913971ef)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95917
Tested-by: Tomaž Vajngerl 

diff --git a/sd/inc/Outliner.hxx b/sd/inc/Outliner.hxx
index d935d6f1d6a8..39e2720f6a01 100644
--- a/sd/inc/Outliner.hxx
+++ b/sd/inc/Outliner.hxx
@@ -355,6 +355,10 @@ private:
 */
 bool SearchAndReplaceOnce(std::vector<::sd::SearchSelection>* pSelections 
= nullptr);
 
+void sendLOKSearchResultCallback(std::shared_ptr& 
pViewShell,
+ OutlinerView* pOutlinerView,
+ std::vector* 
pSelections);
+
 /** Detect changes of the document or view and react accordingly.  Such
 changes may occur because different calls to
 SearchAndReplace() there usually is user
diff --git a/sd/source/ui/view/Outliner.cxx b/sd/source/ui/view/Outliner.cxx
index e7f676f43e4e..6e982f3d25f7 100644
--- a/sd/source/ui/view/Outliner.cxx
+++ b/sd/source/ui/view/Outliner.cxx
@@ -673,6 +673,66 @@ bool SdOutliner::SearchAndReplaceAll()
 return bRet;
 }
 
+void SdOutliner::sendLOKSearchResultCallback(std::shared_ptr & 
pViewShell,
+ OutlinerView* pOutlinerView,
+ std::vector* 
pSelections)
+{
+std::vector<::tools::Rectangle> aLogicRects;
+pOutlinerView->GetSelectionRectangles(aLogicRects);
+
+// convert to twips if in 100thmm (seems as if LibreOfficeKit is based on 
twips?). Do this
+// here where we have the only place needing this, *not* in 
ImpEditView::GetSelectionRectangles
+// which makes that method unusable for others
+if (pOutlinerView->GetWindow() && MapUnit::Map100thMM == 
pOutlinerView->GetWindow()->GetMapMode().GetMapUnit())
+{
+for (tools::Rectangle& rRectangle : aLogicRects)
+{
+rRectangle = OutputDevice::LogicToLogic(rRectangle, 
MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip));
+}
+}
+
+std::vector aLogicRectStrings;
+std::transform(aLogicRects.begin(), aLogicRects.end(), 
std::back_inserter(aLogicRectStrings),
+[](const ::tools::Rectangle& rRectangle)
+{
+return rRectangle.toString();
+});
+
+OString sRectangles = comphelper::string::join("; ", aLogicRectStrings);
+
+if (!pSelections)
+{
+// notify LibreOfficeKit about changed page
+OString aPayload = OString::number(maCurrentPosition.mnPageIndex);
+SfxViewShell& rSfxViewShell = pViewShell->GetViewShellBase();
+rSfxViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_SET_PART, 
aPayload.getStr());
+
+// also about search result selections
+boost::property_tree::ptree aTree;
+aTree.put("searchString", 
mpSearchItem->GetSearchString().toUtf8().getStr());
+aTree.put("highlightAll", false);
+
+boost::property_tree::ptree aChildren;
+boost::property_tree::ptree aChild;
+aChild.put("part", 
OString::number(maCurrentPosition.mnPageIndex).getStr());
+aChild.put("rectangles", sRectangles.getStr());
+aChildren.push_back(std::make_pair("", aChild));
+aTree.add_child("searchResultSelection", aChildren);
+
+std::stringstream aStream;
+boost::property_tree::write_json(aStream, aTree);
+aPayload = aStream.str().c_str();
+
rSfxViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, 
aPayload.getStr());
+}
+else
+{
+sd::SearchSelection aSelection(maCurrentPosition.mnPageIndex, 
sRectangles);
+bool bDuplicate = !pSelections->empty() && pSelections->back() == 
aSelection;
+if (!bDuplicate)
+pSelections->push_back(aSelection);
+}
+}
+
 bool SdOutliner::SearchAndReplaceOnce(std::vector* 
pSelections)
 {
 DetectChange ();
@@ -764,55 +824,7 @@ bool 
SdOutliner::SearchAndReplaceOnce(std::vector* pSelecti
 
 if (pViewShell && comphelper::LibreOfficeKit::isActive() && mbStringFound)
 {
-std::vector<::tools::Rectangle> aLogicRects;
-pOutlinerView->GetSelectionRectangles(aLogicRects);
-
-// convert to twips if in 100thmm (seems as if LibreOfficeKit is based 
on twips?). Do this
-// here where we have the only place needing this, *not* in 
ImpEditView::GetSelectionRectangles