Bug 339894

Summary: Crash when pressing ctrl+x with code folding [KateBuffer::computeFoldingRangeForStartLine]
Product: [Applications] kate Reporter: Emmanuel Lepage Vallée <emmanuel.lepage>
Component: foldingAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: JohnMS, maris.kde, paul, pbs3141, zotovyaa
Priority: NOR    
Version: Git   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: New crash information added by DrKonqi

Description Emmanuel Lepage Vallée 2014-10-12 02:43:19 UTC
This happen with the KDE4 git kate. I failed to reproduce it. It only happened once. I was cutting text in a long lua file. Here is the backtrace:

Application: Kate (kate), signal: Segmentation fault
Using host libthread_db library "/lib64/libthread_db.so.1".
[Current thread is 1 (Thread 0x7fc7a18b2800 (LWP 25930))]

Thread 3 (Thread 0x7fc77d865700 (LWP 26531)):
#0  0x00007fc79d8a6df3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#1  0x00007fc797e441e7 in g_mutex_lock (mutex=mutex@entry=0x7fc7780009c0) at /var/tmp/portage/dev-libs/glib-2.40.0-r1/work/glib-2.40.0/glib/gthread-posix.c:209
#2  0x00007fc797df5860 in g_main_context_acquire (context=0x7fc7780009c0) at /var/tmp/portage/dev-libs/glib-2.40.0-r1/work/glib-2.40.0/glib/gmain.c:3124
#3  0x00007fc797df67c5 in g_main_context_iterate (context=context@entry=0x7fc7780009c0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at /var/tmp/portage/dev-libs/glib-2.40.0-r1/work/glib-2.40.0/glib/gmain.c:3684
#4  0x00007fc797df6a0c in g_main_context_iteration (context=0x7fc7780009c0, may_block=1) at /var/tmp/portage/dev-libs/glib-2.40.0-r1/work/glib-2.40.0/glib/gmain.c:3795
#5  0x00007fc79dc8de36 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#6  0x00007fc79dc57270 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#7  0x00007fc79dc57577 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#8  0x00007fc79db36ba6 in QThread::exec() () from /usr/lib64/qt4/libQtCore.so.4
#9  0x00007fc79dc35033 in QInotifyFileSystemWatcherEngine::run() () from /usr/lib64/qt4/libQtCore.so.4
#10 0x00007fc79db39a14 in QThreadPrivate::start(void*) () from /usr/lib64/qt4/libQtCore.so.4
#11 0x00007fc79d8a4e03 in start_thread () from /lib64/libpthread.so.0
#12 0x00007fc79cbb3dbd in clone () from /lib64/libc.so.6

Thread 2 (Thread 0x7fc77cf64700 (LWP 26601)):
#0  0x00007fc79d8a89ac in pthread_cond_wait () from /lib64/libpthread.so.0
#1  0x00007fc78391427f in QTWTF::TCMalloc_PageHeap::scavengerThread() () from /usr/lib64/qt4/libQtScript.so.4
#2  0x00007fc7839142b9 in QTWTF::TCMalloc_PageHeap::runScavengerThread(void*) () from /usr/lib64/qt4/libQtScript.so.4
#3  0x00007fc79d8a4e03 in start_thread () from /lib64/libpthread.so.0
#4  0x00007fc79cbb3dbd in clone () from /lib64/libc.so.6

Thread 1 (Thread 0x7fc7a18b2800 (LWP 25930)):
[KCrash Handler]
#6  KateBuffer::computeFoldingRangeForStartLine (this=0x2023a60, startLine=startLine@entry=1048) at /home/kde-devel/kde/src/kate/part/document/katebuffer.cpp:545
#7  0x00007fc77fe49e56 in KateIconBorder::showBlock (this=0x40e9ef0) at /home/kde-devel/kde/src/kate/part/view/kateviewhelpers.cpp:1892
#8  0x00007fc79dc731ae in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib64/qt4/libQtCore.so.4
#9  0x00007fc79dc770e2 in QObject::event(QEvent*) () from /usr/lib64/qt4/libQtCore.so.4
#10 0x00007fc79ee655cc in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#11 0x00007fc79ee6d159 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#12 0x00007fc79fc5bdca in KApplication::notify (this=0x7fff99050700, receiver=0x40e9f88, event=0x7fff99050230) at /home/kde-devel/kde/src/kdelibs/kdeui/kernel/kapplication.cpp:311
#13 0x00007fc79dc5939d in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/qt4/libQtCore.so.4
#14 0x00007fc79dc916b4 in QTimerInfoList::activateTimers() () from /usr/lib64/qt4/libQtCore.so.4
#15 0x00007fc79dc8dc21 in timerSourceDispatch(_GSource*, int (*)(void*), void*) () from /usr/lib64/qt4/libQtCore.so.4
#16 0x00007fc797df6704 in g_main_dispatch (context=0x1ace530) at /var/tmp/portage/dev-libs/glib-2.40.0-r1/work/glib-2.40.0/glib/gmain.c:3064
#17 g_main_context_dispatch (context=context@entry=0x1ace530) at /var/tmp/portage/dev-libs/glib-2.40.0-r1/work/glib-2.40.0/glib/gmain.c:3663
#18 0x00007fc797df6968 in g_main_context_iterate (context=context@entry=0x1ace530, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at /var/tmp/portage/dev-libs/glib-2.40.0-r1/work/glib-2.40.0/glib/gmain.c:3734
#19 0x00007fc797df6a0c in g_main_context_iteration (context=0x1ace530, may_block=1) at /var/tmp/portage/dev-libs/glib-2.40.0-r1/work/glib-2.40.0/glib/gmain.c:3795
#20 0x00007fc79dc8de15 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#21 0x00007fc79ef13e46 in QGuiEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtGui.so.4
#22 0x00007fc79dc57270 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#23 0x00007fc79dc57577 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/qt4/libQtCore.so.4
#24 0x00007fc79dc5ee6b in QCoreApplication::exec() () from /usr/lib64/qt4/libQtCore.so.4
#25 0x00007fc7a14f0145 in kdemain (argc=<optimized out>, argv=<optimized out>) at /home/kde-devel/kde/src/kate/kate/app/katemain.cpp:381
#26 0x00007fc79caed975 in __libc_start_main () from /lib64/libc.so.6
#27 0x0000000000400941 in _start ()
Comment 1 Dominik Haumann 2014-10-12 09:06:51 UTC
The code for this is:

522:KTextEditor::Range KateBuffer::computeFoldingRangeForStartLine (int startLine)
...
539:  ensureHighlighted (startLine);
540:  Kate::TextLine startTextLine = plainLine (startLine);
541:  
542:  /**
543:   * return if no folding start!
544:   */
545:  if (!startTextLine->markedAsFoldingStart ())
546:    return KTextEditor::Range::invalid(); 

Maybe startTextLine is invalid? startLine is 1048 in the trace above, so that number looks good.

Probably very hard to reproduce and fix.
Comment 2 Paul 2015-03-08 22:10:59 UTC
Created attachment 91498 [details]
New crash information added by DrKonqi

kate (3.14.4) on KDE Platform 4.14.4 using Qt 4.8.6

This happened for me when I attempted to cut a large chunk of bash code using ctrl-x (fedora 21, kate-4.14.3-3.fc21.x86_64)

-- Backtrace (Reduced):
#6  0x00007f2232208404 in KateBuffer::computeFoldingRangeForStartLine(int) () at /lib64/libkatepartinterfaces.so.4
#7  0x00007f2232299aae in KateIconBorder::showBlock() () at /lib64/libkatepartinterfaces.so.4
[...]
#9  0x00007f224b9642a3 in QObject::event(QEvent*) (this=0x3153fd8, e=<optimized out>) at kernel/qobject.cpp:1253
#10 0x00007f224c83eefc in QApplicationPrivate::notify_helper(QObject*, QEvent*) (this=this@entry=0x23bb540, receiver=receiver@entry=0x3153fd8, e=e@entry=0x7fff23831dc0) at kernel/qapplication.cpp:4565
#11 0x00007f224c845958 in QApplication::notify(QObject*, QEvent*) (this=this@entry=0x7fff238322c0, receiver=receiver@entry=0x3153fd8, e=e@entry=0x7fff23831dc0) at kernel/qapplication.cpp:4351
Comment 3 Māris Nartišs 2015-04-16 09:21:31 UTC
I was deleting in a fast way some parts of not so long HTML5 document and got the same crash. Unfortunately backtrace was incomplete. Editing the same file once more went just fine. A timing issue?

kate: 3.14.6
KDE SC: 4.14.6
Gentoo ~AMD64
Comment 4 Christoph Cullmann 2015-10-04 11:38:58 UTC
Git commit 4e08d37ee449a77d068e74cb135b90c84860b460 by Christoph Cullmann.
Committed on 04/10/2015 at 11:38.
Pushed by cullmann into branch 'master'.

validate line before calling folding stuff

M  +1    -1    src/printing/kateprinter.h
M  +2    -2    src/view/kateview.cpp
M  +5    -4    src/view/kateviewhelpers.cpp

http://commits.kde.org/ktexteditor/4e08d37ee449a77d068e74cb135b90c84860b460
Comment 5 Dominik Haumann 2015-10-09 11:57:58 UTC
*** Bug 352585 has been marked as a duplicate of this bug. ***
Comment 6 Kevin Funk 2016-05-09 17:53:09 UTC
*** Bug 362858 has been marked as a duplicate of this bug. ***
Comment 7 Kåre Särs 2017-06-16 12:27:03 UTC
*** Bug 381275 has been marked as a duplicate of this bug. ***