Bug 496612

Summary: Kate crashes when pasting in overwrite mode (under specific circumstances)
Product: [Applications] kate Reporter: dedale
Component: applicationAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: christoph
Priority: NOR    
Version First Reported In: 24.08.1   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Screen recording showcasing the crash

Description dedale 2024-11-23 17:17:58 UTC
Created attachment 176065 [details]
Screen recording showcasing the crash

SUMMARY
Kate crashes when pasting in overwrite mode (if pasting creates additional lines and the cursor is on the first character of a line)

STEPS TO REPRODUCE
1. Open or create file using Kate
2. Copy several lines of text
3. Set Kate to Overwrite mode
4. Place the cursor on the first character of one of the last lines of the file
5. If pasting forces  Kate to create additional lines, the program will crash

OBSERVED RESULT
Crash to desktop

EXPECTED RESULT
Pasting lines and not crashing to desktop

SOFTWARE/OS VERSIONS 
Linux/KDE Plasma: 
KDE Plasma Version:  6.2.0
KDE Frameworks Version:  6.7.0
Qt Version:   6.7.2
X11

Reproduced it on two different Laptops, using Void Linux and EndeavourOS.
The crash is present on Kate 24.08.1 and on the nightly Appimage (kate-master-8492-linux-gcc-x86_64.AppImage)
Comment 1 Christoph Cullmann 2024-11-23 17:31:23 UTC
Can reproduce. Will take a look.
Comment 2 Christoph Cullmann 2024-11-23 17:52:52 UTC
Git commit dee786898a0d6077884c3f4c425c923ceca0937e by Christoph Cullmann.
Committed on 23/11/2024 at 17:52.
Pushed by cullmann into branch 'master'.

don't crash on insert at lastLine + 1

easy to trigger with overwrite paste

M  +19   -0    autotests/src/kateview_test.cpp
M  +1    -0    autotests/src/kateview_test.h
M  +1    -1    src/document/katedocument.cpp

https://invent.kde.org/frameworks/ktexteditor/-/commit/dee786898a0d6077884c3f4c425c923ceca0937e
Comment 3 Christoph Cullmann 2024-11-23 17:53:18 UTC
Thanks for the precise bug report, added a test, too, that we don't regress.