sw/source/uibase/docvw/edtwin2.cxx |   30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

New commits:
commit 211099533e01f74d3d364b54e40d94c6d3bbe37d
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Jun 23 01:10:51 2025 +0500
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jun 26 18:04:17 2025 +0200

    tdf#167165: catch possible exceptions when trying to get HyperLinkName
    
    The bugdoc has an image beneath the ToC. Moving the mouse cursor close
    to the ToC's page numbers, the tooltip is generated; but the position
    is over the image (aPos = {Node: {[75] {GrfNode}} Content: {0}}), and
    that's what an SwXTextRange is generated from: xRange->m_pMark = NULL.
    
    Trying to get its properties throws with this call stack:
      vcruntime140d.dll!_CxxThrowException(void * pExceptionObject, const 
_s__ThrowInfo * pThrowInfo) Line 79
      swlo.dll!SwXTextRange::getPropertyValue(const rtl::OUString & 
rPropertyName) Line 1498
      swlo.dll!SwEditWin::RequestHelp(const HelpEvent & rEvt) Line 456
      vcllo.dll!ImplHandleMouseHelpRequest(vcl::Window * pChild, const Point & 
rMousePos) Line 186
      vcllo.dll!ImplHandleMouseEvent(const VclPtr<vcl::Window> & xWindow, 
NotifyEventType nSVEvent, bool bMouseLeave, __int64 nX, __int64 nY, unsigned 
__int64 nMsgTime, unsigned short nCode, MouseEventModifiers nMode) Line 738
      vcllo.dll!ImplHandleSalMouseMove(vcl::Window * pWindow, const 
SalMouseEvent * pEvent) Line 2330
      vcllo.dll!ImplWindowFrameProc(vcl::Window * _pWindow, SalEvent nEvent, 
const void * pEvent) Line 2663
      vcllo.dll!SalFrame::CallCallback(SalEvent nEvent, const void * pEvent) 
Line 310
      vclplug_winlo.dll!ImplHandleMouseMsg(HWND__ * hWnd, unsigned int nMsg, 
unsigned __int64 wParam, __int64 lParam) Line 3322
    
    The exception wasn't caught, and crashed.
    
    Change-Id: I9e80c1fc5f78771fce2ec6fe047dfe3d37e0e60b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186806
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit c9c96987c31efe7108d0588ef097e952d623238c)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186937
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/source/uibase/docvw/edtwin2.cxx 
b/sw/source/uibase/docvw/edtwin2.cxx
index c4f52ad07c85..0265efc15b10 100644
--- a/sw/source/uibase/docvw/edtwin2.cxx
+++ b/sw/source/uibase/docvw/edtwin2.cxx
@@ -52,6 +52,7 @@
 #include <IDocumentRedlineAccess.hxx>
 #include <txtfrm.hxx>
 #include <ndtxt.hxx>
+#include <comphelper/diagnose_ex.hxx>
 #include <comphelper/lok.hxx>
 #include <authfld.hxx>
 
@@ -452,20 +453,27 @@ void SwEditWin::RequestHelp(const HelpEvent &rEvt)
                     rtl::Reference<SwXTextRange> 
xRange(SwXTextRange::CreateXTextRange(
                         *(m_rView.GetDocShell()->GetDoc()), aPos, &aPos));
 
-                    OUString sName;
-                    xRange->getPropertyValue(u"HyperLinkName"_ustr) >>= sName;
-                    if (!sName.isEmpty())
+                    try
                     {
-                        bScreenTip = true;
-                        OUStringBuffer sStrBuffer(sName);
-                        sal_Int32 nTextLen = sText.getLength();
-                        sal_Int32 nNameLen = sName.getLength();
-                        if (nTextLen > 0 && nNameLen > nTextLen)
+                        OUString sName;
+                        xRange->getPropertyValue(u"HyperLinkName"_ustr) >>= 
sName;
+                        if (!sName.isEmpty())
                         {
-                            for (sal_Int32 i = nTextLen - 1; i < nNameLen; i 
+= nTextLen)
-                                sStrBuffer.insert(i + 1, std::u16string_view(u"
"));
+                            bScreenTip = true;
+                            OUStringBuffer sStrBuffer(sName);
+                            sal_Int32 nTextLen = sText.getLength();
+                            sal_Int32 nNameLen = sName.getLength();
+                            if (nTextLen > 0 && nNameLen > nTextLen)
+                            {
+                                for (sal_Int32 i = nTextLen - 1; i < nNameLen; 
i += nTextLen)
+                                    sStrBuffer.insert(i + 1, 
std::u16string_view(u"
"));
+                            }
+                            sText = sStrBuffer.makeStringAndClear() + "
" + sText;
                         }
-                        sText = sStrBuffer.makeStringAndClear() + "
" + sText;
+                    }
+                    catch (uno::RuntimeException&)
+                    {
+                        DBG_UNHANDLED_EXCEPTION("sw.ui", "failed to retrieve 
hyperlink name");
                     }
                 }
                 break;

Reply via email to