Bug 313769

Summary: [unit test] crash in KateViewInternal::viewLineOffset()
Product: [Applications] kate Reporter: Dominik Haumann <dhaumann>
Component: partAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: critical CC: christoph
Priority: NOR Keywords: testcase
Version: Git   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 4.11
Sentry Crash Report:
Attachments: file to reproduce the crash

Description Dominik Haumann 2013-01-23 15:19:04 UTC
Thread 1 (Thread 0x7f7285b22780 (LWP 7694)):
[KCrash Handler]
#5  0x00007f72810d8d25 in raise () from /lib64/libc.so.6
#6  0x00007f72810da1a8 in abort () from /lib64/libc.so.6
#7  0x00007f7282460c14 in qt_message_output (msgType=msgType@entry=QtFatalMsg, buf=<optimized out>) at global/qglobal.cpp:2323
#8  0x00007f7282460dc8 in qt_message(QtMsgType, const char *, typedef __va_list_tag __va_list_tag *) (msgType=msgType@entry=QtFatalMsg, msg=msg@entry=0x7f72825c9ac8 "ASSERT: \"%s\" in file %s, line %d", ap=ap@entry=0x7fffc5115358) at global/qglobal.cpp:2369
#9  0x00007f7282460f54 in qFatal (msg=msg@entry=0x7f72825c9ac8 "ASSERT: \"%s\" in file %s, line %d") at global/qglobal.cpp:2552
#10 0x00007f7282460f9a in qt_assert (assertion=<optimized out>, file=<optimized out>, line=<optimized out>) at global/qglobal.cpp:2018
#11 0x00007f727536e43a in KateViewInternal::viewLineOffset (this=0x2a0d9f0, virtualCursor=..., offset=0, keepX=false) at /home/dhaumann/local/projects/kate/part/view/kateviewinternal.cpp:1329
#12 0x00007f727536b3ae in KateViewInternal::makeVisible (this=0x2a0d9f0, c=..., endCol=0, force=false, center=true, calledExternally=true) at /home/dhaumann/local/projects/kate/part/view/kateviewinternal.cpp:631
#13 0x00007f72753715d4 in KateViewInternal::updateCursor (this=0x2a0d9f0, newCursor=..., force=false, center=true, calledExternally=true) at /home/dhaumann/local/projects/kate/part/view/kateviewinternal.cpp:1878
#14 0x00007f727535f191 in KateView::setCursorPositionInternal (this=0x2603580, position=..., tabwidth=1, calledExternally=true) at /home/dhaumann/local/projects/kate/part/view/kateview.cpp:1206
#15 0x00007f72753637ce in KateView::setCursorPosition (this=0x2603580, position=...) at /home/dhaumann/local/projects/kate/part/view/kateview.cpp:2286
#16 0x00007f72752d9eba in KateUndoGroup::undo (this=0x2e99cd0, view=0x2603580) at /home/dhaumann/local/projects/kate/part/undo/kateundo.cpp:270
#17 0x00007f72752de2f5 in KateUndoManager::undo (this=0x25ce590) at /home/dhaumann/local/projects/kate/part/undo/kateundomanager.cpp:242
#18 0x00007f72752b4a5d in KateDocument::undo (this=0x25faf00) at /home/dhaumann/local/projects/kate/part/document/katedocument.cpp:1378
#19 0x00007f72752abad2 in KateDocument::qt_static_metacall (_o=0x25faf00, _c=QMetaObject::InvokeMetaMethod, _id=37, _a=0x7fffc5115cd0) at /home/dhaumann/local/projects/kate/build/part/katedocument.moc:272
#20 0x00007f728257c0ff in QMetaObject::activate (sender=0x2683590, m=<optimized out>, local_signal_index=<optimized out>, argv=0x7fffc5115cd0) at kernel/qobject.cpp:3548
#21 0x00007f72831bf652 in QAction::triggered(bool) () from /usr/lib64/libQtGui.so.4
#22 0x00007f72831bf840 in QAction::activate(QAction::ActionEvent) () from /usr/lib64/libQtGui.so.4
#23 0x00007f72831bf9a7 in QAction::event(QEvent*) () from /usr/lib64/libQtGui.so.4
#24 0x00007f7283dffc27 in KAction::event(QEvent*) () from /usr/lib64/libkdeui.so.5
#25 0x00007f72831c585c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQtGui.so.4
#26 0x00007f72831c9cda in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQtGui.so.4
#27 0x00007f7283ed9636 in KApplication::notify(QObject*, QEvent*) () from /usr/lib64/libkdeui.so.5
#28 0x00007f7282566bfe in QCoreApplication::notifyInternal (this=0x7fffc51176a0, receiver=0x2683590, event=0x7fffc5116270) at kernel/qcoreapplication.cpp:946
#29 0x00007f72831f6504 in ?? () from /usr/lib64/libQtGui.so.4
#30 0x00007f72831f7b33 in ?? () from /usr/lib64/libQtGui.so.4
#31 0x00007f72831cb9b9 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQtGui.so.4
#32 0x00007f7283ed9636 in KApplication::notify(QObject*, QEvent*) () from /usr/lib64/libkdeui.so.5
#33 0x00007f7282566bfe in QCoreApplication::notifyInternal (this=0x7fffc51176a0, receiver=0x2a0d9f0, event=0x7fffc5116840) at kernel/qcoreapplication.cpp:946
#34 0x00007f7283261e4a in ?? () from /usr/lib64/libQtGui.so.4
#35 0x00007f7283262281 in ?? () from /usr/lib64/libQtGui.so.4
#36 0x00007f728323f9b8 in QApplication::x11ProcessEvent(_XEvent*) () from /usr/lib64/libQtGui.so.4
#37 0x00007f7283265f72 in ?? () from /usr/lib64/libQtGui.so.4
#38 0x00007f727e72c3b5 in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
#39 0x00007f727e72c6e8 in ?? () from /usr/lib64/libglib-2.0.so.0
#40 0x00007f727e72c7a4 in g_main_context_iteration () from /usr/lib64/libglib-2.0.so.0
#41 0x00007f7282595116 in QEventDispatcherGlib::processEvents (this=0x2131b80, flags=...) at kernel/qeventdispatcher_glib.cpp:424
#42 0x00007f7283265bee in ?? () from /usr/lib64/libQtGui.so.4
#43 0x00007f728256594f in QEventLoop::processEvents (this=this@entry=0x7fffc5117630, flags=...) at kernel/qeventloop.cpp:149
#44 0x00007f7282565bd8 in QEventLoop::exec (this=0x7fffc5117630, flags=...) at kernel/qeventloop.cpp:204
#45 0x00007f728256a878 in QCoreApplication::exec () at kernel/qcoreapplication.cpp:1218
#46 0x00007f7285710676 in kdemain (argc=1, argv=0x7fffc5118198) at /home/dhaumann/local/projects/kate/kwrite/kwritemain.cpp:707
#47 0x000000000040097e in main (argc=1, argv=0x7fffc5118198) at /home/dhaumann/local/projects/kate/build/kwrite/kwrite_dummy.cpp:3


Reproducible: Sometimes

Steps to Reproduce:
1. open huge file with highlighting and folding
2. play around with ctrl+shift+up/down for a long time
3. undo/redo a lot, toggle some folds, undo/redo...

At some point, it crashes by hitting an assert, backtrace attached.
I had two views of the same document open, maybe this makes a difference.



The assert was added in 2002 with commit 9f211545dcbc1eb41fc20687351784cf188442b0, at that time, it read:
Q_ASSERT(thisRange.visibleLine == virtualCursor.line);
Comment 1 Dominik Haumann 2013-01-23 16:35:36 UTC
Created attachment 76667 [details]
file to reproduce the crash

reproduce as follows:
1. open kwrite, resize window to 1280x1000 pixel
2. open test file "crash.cpp"
3. <cursor down><cursor down><ctrl+shift+end><ctrl+shift+cursor-up>
4. <ctrl+pos1>
5. <ctrl+shift+minus>
6. undo, redo, undo

The last undo crashes Kate Part.
If it does not crash Kate, try this:
- enable dynamic word wrap
- make sure the width of the view is wide enough so that no line is dynamically wrapped
- make sure the height of the window is small enough, so that the vertical scrollbar is active
- vary the width / height of kwrite, then try step 1-6 again.
Comment 2 Dominik Haumann 2013-01-24 14:15:07 UTC
Git commit 30acc3aaaf10b42167dfb9144938f6a82b88384f by Dominik Haumann.
Committed on 24/01/2013 at 15:14.
Pushed by dhaumann into branch 'master'.

add unit test for crash 313769

enable dynamic word wrap

1. open kwrite, resize window to 900x1000 pixel
2. open test file "data/bug313769.cpp"
3. <cursor down><cursor down><ctrl+shift+end><ctrl+shift+cursor-up>
4. <ctrl+pos1>
5. <ctrl+shift+minus>
6. undo, redo, undo

M  +11   -0    part/tests/CMakeLists.txt
A  +95   -0    part/tests/bug313769.cpp     [License: LGPL (v2+)]
A  +40   -0    part/tests/bug313769.h     [License: LGPL (v2+)]
A  +74   -0    part/tests/data/bug313769.cpp     [License: UNKNOWN]  *

The files marked with a * at the end have a non valid license. Please read: http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


http://commits.kde.org/kate/30acc3aaaf10b42167dfb9144938f6a82b88384f
Comment 3 Christoph Cullmann 2013-03-27 20:35:26 UTC
Could you try to update this unit test for the new folding code?
Comment 4 Dominik Haumann 2013-04-11 19:46:23 UTC
Git commit 078f0bc871cd77cf91f99803247e47eda899202b by Dominik Haumann.
Committed on 11/04/2013 at 21:46.
Pushed by dhaumann into branch 'master'.

enable folding unit test again

With the previous folding code, this lead to a crash due to invalid
KateViewLine access. What to do, remove unit test?

M  +8    -8    tests/CMakeLists.txt
M  +13   -8    tests/bug313769.cpp

http://commits.kde.org/kate/078f0bc871cd77cf91f99803247e47eda899202b
Comment 5 Dominik Haumann 2013-04-11 19:56:36 UTC
To me it looks like the the expression in the assert statement
      Q_ASSERT(thisLine.virtualLine() == (int) doc()->getVirtualLine(virtualCursor.line()));
now is true, implying that previously we the folding very likely lead to this mismatch.

Should we even remove the unit test, as we actually do not really know what it now tests? ;)