Bug 495925

Summary: Kate frequently crashes in Kate::TextBlock::startLine() while typing with today's git master
Product: [Applications] kate Reporter: Nate Graham <nate>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: crash Keywords: regression
Priority: NOR    
Version First Reported In: Git   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Nate Graham 2024-11-07 15:28:46 UTC
Happened about 10 times today so far, all of it then typing in a .txt document. Git master, Qt 6.8.0, Fedora 41

Backtrace:

#0  __pthread_kill_implementation
    (threadid=<optimized out>, signo=signo@entry=11, no_tid=no_tid@entry=0)
    at pthread_kill.c:44
#1  0x00007f53e9280793 in __pthread_kill_internal
    (threadid=<optimized out>, signo=11) at pthread_kill.c:78
#2  0x00007f53e9227d1e in __GI_raise (sig=11) at ../sysdeps/posix/raise.c:26
#3  0x00007f53ebe575ab in KCrash::defaultCrashHandler (sig=11)
    at /home/nate/kde/src/kcrash/src/kcrash.cpp:596
#4  0x00007f53e9227dd0 in <signal handler called> () at /lib64/libc.so.6
#5  std::vector<int, std::allocator<int> >::operator[]
    (this=<optimized out>, __n=<optimized out>)
    at /usr/include/c++/14/bits/stl_vector.h:1128
#6  Kate::TextBlock::startLine (this=0xffffffffffffffff)
    at /home/nate/kde/src/ktexteditor/src/buffer/katetextblock.cpp:33
#7  0x00007f53ec7494d7 in KTextEditor::ViewPrivate::updateRangesIn
    (this=0xffffffffffffffff, activationType=(unknown: 0x3e0718e8))
    at /home/nate/kde/src/ktexteditor/src/view/kateview.cpp:4825
#8  0x00007f53ec74a2b8 in QHashPrivate::iterator<QHashPrivate::Node<Kate::TextRange*, QHashDummyValue> >::node (this=0x3a8778f0) at /usr/include/qt6/QtCore/qhash.h:784
#9  QHash<Kate::TextRange*, QHashDummyValue>::emplace_helper<QHashDummyValue const&>
    (this=0x7ffc78b11b40, key=@0x7ffc78b11b58: 0x21)
    at /usr/include/qt6/QtCore/qhash.h:1374
#10 QHash<Kate::TextRange*, QHashDummyValue>::emplace<QHashDummyValue const&>
    (this=0x7ffc78b11b40, key=@0x7ffc78b11b58: 0x21)
    at /usr/include/qt6/QtCore/qhash.h:1353
#11 QHash<Kate::TextRange*, QHashDummyValue>::emplace<QHashDummyValue const&>
    (this=0x7ffc78b11b40, key=<optimized out>)
    at /usr/include/qt6/QtCore/qhash.h:1344
#12 QHash<Kate::TextRange*, QHashDummyValue>::insert
    (key=<optimized out>, value=<optimized out>, this=0x7ffc78b11b40)
    at /usr/include/qt6/QtCore/qhash.h:1322
#13 QSet<Kate::TextRange*>::insert
    (value=<synthetic pointer>: <optimized out>, this=0x7ffc78b11b40)
    at /usr/include/qt6/QtCore/qset.h:157
#14 KTextEditor::ViewPrivate::updateRangesIn
    (this=0x7f53e994d172 <QObject::event(QEvent*)+354>, activationType=(unknown: 0x2)) at /home/nate/kde/src/ktexteditor/src/view/kateview.cpp:4868
#15 0x00007f53e98f3a38 in QCoreApplication::notifyInternal2
    (receiver=0x7f53eae3d6b8 <QApplicationPrivate::notify_helper(QObject*, QEvent*)+136>, event=0x3dbfc570)
    at /usr/src/debug/qt6-qtbase-6.8.0-4.fc41.x86_64/src/corelib/kernel/qcoreapplication.cpp:1165
Comment 1 Bug Janitor Service 2024-11-07 17:22:51 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/753
Comment 2 Waqar Ahmed 2024-11-07 18:44:09 UTC
Git commit 792a1786cdfa4ec1cb5b9fa3ca710ffe41b55ed7 by Waqar Ahmed.
Committed on 07/11/2024 at 17:21.
Pushed by cullmann into branch 'master'.

Fix crash if feedback or dyn attr is cleared before deletion

We only notify about deleted range in the dtor if a range has feedback
or a dynamic attribute. That will not work if someone clears the
feedback or attribute before deletion.

To safeguard against this, notify about this change if the feedback/
attribute gets unset.

Note that the parameter is called "deletedRange" which isn't really
accurate anymore and needs to be renamed but I am not really sure
what to name it.

Ideally the view or anyone else wouldn't store non-owning range pointers
like this. I don't have any good ideas about a safer "handle" that also
performs well atm so leaving it as is.

M  +42   -0    autotests/src/movingrange_test.cpp
M  +2    -0    autotests/src/movingrange_test.h
M  +17   -2    src/buffer/katetextrange.cpp

https://invent.kde.org/frameworks/ktexteditor/-/commit/792a1786cdfa4ec1cb5b9fa3ca710ffe41b55ed7