sw/source/core/txtnode/modeltoviewhelper.cxx |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

New commits:
commit 2b089278f3732ea35b14cd4c577b6f496bfc0998
Author:     Miklos Vajna <[email protected]>
AuthorDate: Mon Jan 5 08:49:57 2026 +0100
Commit:     Miklos Vajna <[email protected]>
CommitDate: Tue Jan 6 19:00:57 2026 +0100

    sw: fix crash in the ModelToViewHelper ctor
    
    gdb backtrace on the core file from the crash report:
    
            #5  0x0000000000afc0ee in std::__glibcxx_assert_fail(char const*, 
int, char const*, char const*) ()
            #6  0x0000727cd30229b1 in std::deque<std::pair<sw::mark::Fieldmark 
const*, bool>, std::allocator<std::pair<sw::mark::Fieldmark const*, bool> > 
>::pop_back (this=0x7ffc1ea0f8e0)
                at 
/opt/rh/devtoolset-12/root/usr/include/c++/12/bits/stl_deque.h:1597
            #7  std::deque<std::pair<sw::mark::Fieldmark const*, bool>, 
std::allocator<std::pair<sw::mark::Fieldmark const*, bool> > >::pop_back 
(this=0x7ffc1ea0f8e0)
                at 
/opt/rh/devtoolset-12/root/usr/include/c++/12/bits/stl_deque.h:1597
            #8  ModelToViewHelper::ModelToViewHelper 
(this=this@entry=0x7ffc1ea0fb40, rNode=..., pLayout=0x631dce00,
                eMode=eMode@entry=(ExpandMode::ExpandFields | 
ExpandMode::ExpandFootnote | ExpandMode::ReplaceMode | 
ExpandMode::HideFieldmarkCommands))
                at sw/source/core/txtnode/modeltoviewhelper.cxx:207
            #9  0x0000727cd311cea2 in SwXFlatParagraphIterator::getNextPara 
(this=0x64417ab0)
                at sw/source/core/unocore/unoflatpara.cxx:485
            ...
            #12 0x0000727cd2c23b4f in SwDoc::StartGrammarChecking 
(this=<optimized out>, bSkipStart=bSkipStart@entry=false)
                at sw/source/core/doc/docnew.cxx:184
    
    and:
    
            (gdb) frame 8
            #8  ModelToViewHelper::ModelToViewHelper 
(this=this@entry=0x7ffc1ea0fb40, rNode=..., pLayout=0x631dce00,
                eMode=eMode@entry=(ExpandMode::ExpandFields | 
ExpandMode::ExpandFootnote | ExpandMode::ReplaceMode | 
ExpandMode::HideFieldmarkCommands))
                at sw/source/core/txtnode/modeltoviewhelper.cxx:207
            207                         startedFields.pop_back();
            (gdb) print startedFields
            $2 = std::deque with 0 elements
    
    We have no reproducer for this, but seems the grammar checker is somehow
    invoked on an inconsistent model where the start and end field mark
    dummy characters are not balanced. Leave the assert in place, so
    possibly a later debug build can find a reproducer; but also check for
    this to avoid a crash in product builds.
    
    Change-Id: Ic9696e32bf344b336800bfa475f506e3cc103ef6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196615
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins

diff --git a/sw/source/core/txtnode/modeltoviewhelper.cxx 
b/sw/source/core/txtnode/modeltoviewhelper.cxx
index 7b33bb32baa8..2573d273e460 100644
--- a/sw/source/core/txtnode/modeltoviewhelper.cxx
+++ b/sw/source/core/txtnode/modeltoviewhelper.cxx
@@ -204,7 +204,10 @@ ModelToViewHelper::ModelToViewHelper(const SwTextNode 
&rNode,
                 case CH_TXT_ATR_FIELDEND:
                 {
                     assert(startedFields.back().first == 
rIDMA.getFieldmarkAt(SwPosition(rNode, i)));
-                    startedFields.pop_back();
+                    if (!startedFields.empty())
+                    {
+                        startedFields.pop_back();
+                    }
                     aHiddenMulti.Select({i, i}, true);
                     break;
                 }

Reply via email to