accessibility/inc/extended/textwindowaccessibility.hxx    |    1 +
 accessibility/source/extended/textwindowaccessibility.cxx |   11 +++++++++++
 2 files changed, 12 insertions(+)

New commits:
commit 9a07b6c34c12d998b0428a5f70a4833bade3ef1f
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Oct 31 20:46:56 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Oct 31 19:13:47 2024 +0100

    tdf#163697: avoid premature handling of following notifications
    
    This avoids re-entry to Document::handleParagraphNotifications, which
    already was known to be problematic (see comments in Document::Notify,
    and m_bSelectionChangedNotification introduced to avoid one such case).
    
    Change-Id: I9e0b451f13ad109d08b1afc9cc0346cd6049b026
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175879
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/accessibility/inc/extended/textwindowaccessibility.hxx 
b/accessibility/inc/extended/textwindowaccessibility.hxx
index 44652bc87d3c..e998ac3c443e 100644
--- a/accessibility/inc/extended/textwindowaccessibility.hxx
+++ b/accessibility/inc/extended/textwindowaccessibility.hxx
@@ -572,6 +572,7 @@ private:
 
     std::queue< ::TextHint > m_aParagraphNotifications;
     bool m_bSelectionChangedNotification;
+    bool m_bInParagraphNotificationsHandler = false;
 };
 
 }
diff --git a/accessibility/source/extended/textwindowaccessibility.cxx 
b/accessibility/source/extended/textwindowaccessibility.cxx
index ac8c0a736ab1..8692e5fcd0ff 100644
--- a/accessibility/source/extended/textwindowaccessibility.cxx
+++ b/accessibility/source/extended/textwindowaccessibility.cxx
@@ -1670,6 +1670,16 @@ Document::changeParagraphText(::sal_uInt32 nNumber, 
::sal_uInt16 nBegin, ::sal_u
 
 void Document::handleParagraphNotifications()
 {
+    // Recursion is possible, e.g. when SfxHintId::TextParaInserted is being 
handled,
+    // and TextEngine::GetTextHeight is called for the paragraph being 
inserted; that
+    // tries to handle the following SfxHintId::TextFormatPara notification at 
the
+    // moment when the respective element hasn't yet been inserted into 
m_aParagraphs,
+    // which could crash. Therefore, re-entry is not allowed. The handling is 
done in
+    // a loop anyway, so it will process all of them in due order.
+    // See also comments in Document::Notify.
+    if (m_bInParagraphNotificationsHandler)
+        return;
+    m_bInParagraphNotificationsHandler = true;
     while (!m_aParagraphNotifications.empty())
     {
         ::TextHint aHint(m_aParagraphNotifications.front());
@@ -1856,6 +1866,7 @@ void Document::handleParagraphNotifications()
             break;
         }
     }
+    m_bInParagraphNotificationsHandler = false;
     if (m_bSelectionChangedNotification)
     {
         m_bSelectionChangedNotification = false;

Reply via email to