Bug 462793

Summary: Crash when pressing ctrl-z after reloading a file that was modified
Product: [Applications] kate Reporter: Foxite <the>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: the
Priority: NOR Keywords: drkonqi
Version First Reported In: 22.08.3   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Foxite 2022-12-08 17:16:07 UTC
Application: kate (22.08.3)

Qt Version: 5.15.7
Frameworks Version: 5.100.0
Operating System: Linux 5.15.81-1-lts x86_64
Windowing System: Wayland
Distribution: "Arch Linux"
DrKonqi: 5.26.4 [KCrashBackend]

-- Information about the crash:
drkonqi gave me a bunch of duplicates for this, all of which were closed as fixed many years ago.

I'm having extremely mixed results when trying to reduce the reproduction steps. Slight variations can make the crash inconsistent, but these steps let me consistently reproduce it, every time. Follow these steps exactly to be sure. A lot of it is probably unnecessary, but again I'm having trouble figuring out what. I suppose there may also be more to it than what I've determined.

Following these steps **exactly** lets me consistently reproduce this crash:
1. Open kate, create a new empty file, and save it. Make sure it's in your recent documents. Close kate.
2. Open kate and open the file.
3. Write 9 lines of "bla" followed by an empty line.
4. Save the file.
5. Using any tool other than Kate, blank the file. Make sure there is no trailing newline in the file.
6. Go back to Kate. It should show you the notification that the file was changed on disk.
7. Press f5 to reload.
8. Press ctrl-z to undo. Kate crashes.

I reproduced this on 2 machines, both of which run Arch linux with KDE on Wayland. Both were fully updated less than a few hours ago, as of this report's submission.

The crash can be reproduced every time.

-- Backtrace:
Application: Kate (kate), signal: Segmentation fault
Content of s_kcrashErrorMessage: std::unique_ptr<char []> = {get() = <optimized out>}
[KCrash Handler]
#6  Kate::TextLineData::markAsModified (modified=<optimized out>, this=<optimized out>) at /usr/src/debug/ktexteditor/ktexteditor-5.100.0/src/buffer/katetextline.h:177
#7  Kate::TextLineData::markAsModified (modified=<optimized out>, this=<optimized out>, this=<optimized out>, modified=<optimized out>) at /usr/src/debug/ktexteditor/ktexteditor-5.100.0/src/buffer/katetextline.h:175
#8  KateModifiedWrapLine::undo (this=0x55816db45310) at /usr/src/debug/ktexteditor/ktexteditor-5.100.0/src/undo/katemodifiedundo.cpp:179
#9  0x00007fc3f0c827ce in KateUndoGroup::undo (view=0x55816e2bd600, this=0x55816d97a3b0) at /usr/src/debug/ktexteditor/ktexteditor-5.100.0/src/undo/kateundo.cpp:245
#10 KateUndoGroup::undo (view=0x55816e2bd600, this=0x55816d97a3b0) at /usr/src/debug/ktexteditor/ktexteditor-5.100.0/src/undo/kateundo.cpp:236
#11 KateUndoManager::undo (this=0x55816e1e4680) at /usr/src/debug/ktexteditor/ktexteditor-5.100.0/src/undo/kateundomanager.cpp:272
#12 KateUndoManager::undo (this=0x55816e1e4680) at /usr/src/debug/ktexteditor/ktexteditor-5.100.0/src/undo/kateundomanager.cpp:265
#13 0x00007fc3f15a3c00 in doActivate<false> (sender=0x55816e286af0, signal_index=4, argv=0x7ffec7135fe0) at kernel/qobject.cpp:3931
#14 0x00007fc3f214cec7 in QAction::triggered (this=this@entry=0x55816e286af0, _t1=<optimized out>) at .moc/moc_qaction.cpp:376
#15 0x00007fc3f21528c7 in QAction::activate (this=0x55816e286af0, event=<optimized out>) at kernel/qaction.cpp:1161
#16 0x00007fc3f215298e in QAction::event (e=<optimized out>, this=<optimized out>) at kernel/qaction.cpp:1086
#17 QAction::event (this=<optimized out>, e=<optimized out>) at kernel/qaction.cpp:1075
#18 0x00007fc3f2159b1c in QApplicationPrivate::notify_helper (this=<optimized out>, receiver=0x55816e286af0, e=0x7ffec7136170) at kernel/qapplication.cpp:3637
#19 0x00007fc3f1572f98 in QCoreApplication::notifyInternal2 (receiver=0x55816e286af0, event=0x7ffec7136170) at kernel/qcoreapplication.cpp:1064
#20 0x00007fc3f1aed2bd in QShortcutMap::dispatchEvent (this=<optimized out>, e=<optimized out>) at kernel/qshortcutmap.cpp:675
#21 0x00007fc3f1ae3b27 in QShortcutMap::tryShortcut (this=0x55816d384c48, e=0x7ffec7136230) at kernel/qshortcutmap.cpp:343
#22 0x00007fc3f1aa3168 in QWindowSystemInterface::handleShortcutEvent (window=<optimized out>, timestamp=3979052, keyCode=90, modifiers=..., nativeScanCode=52, nativeVirtualKey=122, nativeModifiers=20, text=..., autorepeat=false, count=1) at kernel/qwindowsysteminterface.cpp:477
#23 0x00007fc3f1ab8b22 in QGuiApplicationPrivate::processKeyEvent (e=0x55816df70f60) at kernel/qguiapplication.cpp:2398
#24 0x00007fc3f1aa1995 in QWindowSystemInterface::sendWindowSystemEvents (flags=...) at kernel/qwindowsysteminterface.cpp:1169
#25 0x00007fc3ec453995 in userEventSourceDispatch(_GSource*, int (*)(void*), void*) () from /usr/lib/libQt5WaylandClient.so.5
#26 0x00007fc3ef04f87b in g_main_dispatch (context=0x7fc3e4005010) at ../glib/glib/gmain.c:3444
#27 g_main_context_dispatch (context=0x7fc3e4005010) at ../glib/glib/gmain.c:4162
#28 0x00007fc3ef0a6299 in g_main_context_iterate.constprop.0 (context=0x7fc3e4005010, block=1, dispatch=1, self=<optimized out>) at ../glib/glib/gmain.c:4238
#29 0x00007fc3ef04e132 in g_main_context_iteration (context=0x7fc3e4005010, may_block=1) at ../glib/glib/gmain.c:4303
#30 0x00007fc3f15bdc4c in QEventDispatcherGlib::processEvents (this=0x55816d34fb60, flags=...) at kernel/qeventdispatcher_glib.cpp:423
#31 0x00007fc3f156b73c in QEventLoop::exec (this=0x7ffec71365e0, flags=...) at ../../include/QtCore/../../src/corelib/global/qflags.h:69
#32 0x00007fc3f1576269 in QCoreApplication::exec () at ../../include/QtCore/../../src/corelib/global/qflags.h:121
#33 0x00007fc3f1ab3112 in QGuiApplication::exec () at kernel/qguiapplication.cpp:1870
#34 0x00007fc3f2157f2a in QApplication::exec () at kernel/qapplication.cpp:2829
#35 0x000055816d3155d5 in main (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/kate/kate-22.08.3/apps/kate/main.cpp:607
[Inferior 1 (process 25039) detached]

Reported using DrKonqi
Comment 1 Foxite 2022-12-08 17:23:03 UTC
Just confirmed that kwrite has the exact same problem.

I don't know how Kate works under the hood but it *looks* like Kate just integrates KWrite into itself, so the product can probably be changed to kwrite instead of kate.
Comment 2 Bug Janitor Service 2022-12-28 06:48:25 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/459
Comment 3 Waqar Ahmed 2022-12-28 07:05:55 UTC
Git commit 817392a1893a430237340805154e7ddae911e6b4 by Waqar Ahmed.
Committed on 28/12/2022 at 06:47.
Pushed by cullmann into branch 'master'.

Fix crash on undo after reload

When the doc is externally modified we must clear any stored state that
relies on the doc being same.

Checksum check is useless because it is already updated, we must clear
it unconditionally always if m_modOnHD == true

M  +16   -0    src/document/katedocument.cpp
M  +5    -0    src/view/kateview.cpp
M  +7    -0    src/view/kateview.h

https://invent.kde.org/frameworks/ktexteditor/commit/817392a1893a430237340805154e7ddae911e6b4