Bug 479983

Summary: Konsole crashes when selecting unicode glyphs (emoji)
Product: [Applications] konsole Reporter: Oded Arbel <oded>
Component: copy-pasteAssignee: Konsole Developer <konsole-devel>
Status: RESOLVED FIXED    
Severity: normal CC: ak2022dev, akselmo
Priority: NOR Keywords: qt6
Version: 24.01.90   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: DrKonqi crash data, that I couldn't get to submit automatically due to an error response from bugs.kde.org
sample output that causes the crash
A screenshot of how the output looks in Konsole

Description Oded Arbel 2024-01-18 09:29:02 UTC
Created attachment 165001 [details]
DrKonqi crash data, that I couldn't get to submit automatically due to an error response from bugs.kde.org

SUMMARY
Konsole version 24.01.95 installed from Neon testing.

I have a terminal application that outputs some textual report that has unicode glyphs at the end of each line ("emoji"). When I try to use the mouse to select the text, when I get to the part that selects the emoji, Konsole crashes.

I will attach a sample output shortly, as it cannot be posted in the description because bugs.kde.org thinks it is spam, for some weird reason.

So far I reproduced the crash by either:
- double clicking a word at the beginning, then swiping the mouse right to get to the end of the line - when it gets to the last work, before it shows it selected it (and I'm assuming also the emoji that is not separated by space), Konsole crashes. The backtrace for that is attached here.
- triple clicking a line to select the entire line - Konsole markes the whole line as selected, then crashes. I can generate a new backtrace for that if you want.

The crash can be reproduced every time.

STEPS TO REPRODUCE
1. Output text with some emoji in it to Konsole, for example by storing the above output snippet in a file, then `cat`ing it.
2. Use the mouse to select the text that contains the emoji.

OBSERVED RESULT
Konsole crashes

EXPECTED RESULT
Konsole should not crash

SOFTWARE/OS VERSIONS
Qt Version: 6.6.1
Frameworks Version: 5.249.0
Operating System: Linux 6.5.0-14-generic x86_64
Windowing System: Wayland
Distribution: KDE neon Testing Edition

ADDITIONAL INFORMATION
I have BiDi enabled in Konsole, I don't know if it is related, but its about glyphs and rendering, so 🤷

The relevant part of the crash backtrace is probably this:

---8<---
#11 0x00007f97c3cd86f3 in qAbort () at ./src/corelib/global/qglobal.cpp:161
#12 0x00007f97c3cd4055 in qt_message_fatal<QString&> (message=..., context=...) at ./src/corelib/global/qlogging.cpp:2003
#13 qt_message(QtMsgType, const QMessageLogContext &, const char *, typedef __va_list_tag __va_list_tag *) (msgType=msgType@entry=QtFatalMsg, context=..., msg=<optimized out>, ap=ap@entry=0x7fff5daa61e0) at ./src/corelib/global/qlogging.cpp:378
#14 0x00007f97c3cd909f in QMessageLogger::fatal (this=<optimized out>, msg=<optimized out>) at ./src/corelib/global/qlogging.cpp:901
#15 0x00007f97c3ca9261 in qt_assert (assertion=<optimized out>, file=<optimized out>, line=<optimized out>) at ./src/corelib/global/qassert.cpp:68
#16 0x00007f97c50875d7 in ?? () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#17 0x00007f97c508b6ee in ?? () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#18 0x00007f97c5142144 in Konsole::TerminalDisplay::findWordEnd(QPoint const&) () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#19 0x00007f97c5142af1 in Konsole::TerminalDisplay::extendSelection(QPoint const&) () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#20 0x00007f97c5142d3c in Konsole::TerminalDisplay::mouseMoveEvent(QMouseEvent*) () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
---8<---
Comment 1 Oded Arbel 2024-01-18 09:30:50 UTC
Created attachment 165002 [details]
sample output that causes the crash

bugs.kde.org definitely does not like me to post this in a comment...
Comment 2 Oded Arbel 2024-01-18 09:32:41 UTC
Created attachment 165003 [details]
A screenshot of how the output looks in Konsole

The bugzilla rendering is really bad - it probably doesn't detect that the file is UTF-8.
Comment 3 Oded Arbel 2024-01-18 09:34:32 UTC
When tripple clicking to select the line, the crash backtrace looks like this:

---8<---
#11 0x00007f2a032d86f3 in qAbort () at ./src/corelib/global/qglobal.cpp:161
#12 0x00007f2a032d4055 in qt_message_fatal<QString&> (message=..., context=...) at ./src/corelib/global/qlogging.cpp:2003
#13 qt_message(QtMsgType, const QMessageLogContext &, const char *, typedef __va_list_tag __va_list_tag *) (msgType=msgType@entry=QtFatalMsg, context=..., msg=<optimized out>, ap=ap@entry=0x7fff58203050) at ./src/corelib/global/qlogging.cpp:378
#14 0x00007f2a032d909f in QMessageLogger::fatal (this=<optimized out>, msg=<optimized out>) at ./src/corelib/global/qlogging.cpp:901
#15 0x00007f2a032a9261 in qt_assert (assertion=<optimized out>, file=<optimized out>, line=<optimized out>) at ./src/corelib/global/qassert.cpp:68
#16 0x00007f2a046875d7 in ?? () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#17 0x00007f2a0468f0f3 in ?? () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#18 0x00007f2a046c7736 in Konsole::Screen::copyLineToStream(int, int, int, Konsole::TerminalCharacterDecoder*, bool, bool, QFlags<Konsole::Screen::DecodingOption>) const () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#19 0x00007f2a046c7df2 in Konsole::Screen::writeToStream(Konsole::TerminalCharacterDecoder*, int, int, QFlags<Konsole::Screen::DecodingOption>) const () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#20 0x00007f2a046cb634 in Konsole::Screen::text(int, int, QFlags<Konsole::Screen::DecodingOption>) const () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#21 0x00007f2a046cb7da in Konsole::Screen::selectedText(QFlags<Konsole::Screen::DecodingOption>) const () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#22 0x00007f2a046cd066 in Konsole::ScreenWindow::selectedText(QFlags<Konsole::Screen::DecodingOption>) const () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#23 0x00007f2a0473ee4f in Konsole::TerminalDisplay::mouseReleaseEvent(QMouseEvent*) () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
---8<---
Comment 4 Oded Arbel 2024-01-18 09:35:27 UTC
I'm pretty sure this is a regression for 24.02, and I didn't have this issue with 23.08
Comment 5 Akseli Lahtinen 2024-01-18 11:35:15 UTC
Can reproduce

#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0)
    at pthread_kill.c:44
#1  0x00007fc2d40ae8a3 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007fc2d405c8ee in __GI_raise (sig=6) at ../sysdeps/posix/raise.c:26
#3  0x00007fc2d800ef44 in KCrash::defaultCrashHandler (sig=6)
    at /home/akseli/Repositories/kde/src/kcrash/src/kcrash.cpp:586
#4  0x00007fc2d405c9a0 in <signal handler called> () at /lib64/libc.so.6
#5  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0)
    at pthread_kill.c:44
#6  0x00007fc2d40ae8a3 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#7  0x00007fc2d405c8ee in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#8  0x00007fc2d40448ff in __GI_abort () at abort.c:79
#9  0x00007fc2d46e3563 in qAbort ()
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/global/qglobal.cpp:161
#10 0x00007fc2d4728be0 in qt_message_fatal<QString&> (message=..., context=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/global/qlogging.cpp:2003
#11 qt_message(QtMsgType, const QMessageLogContext &, const char *, typedef __va_list_tag __va_list_tag *)
    (msgType=msgType@entry=QtFatalMsg, context=..., msg=msg@entry=0x7fc2d4a79db8 "ASSERT: \"%s\" in file %s, line %d", ap=ap@entry=0x7ffefd52eb00)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/global/qlogging.cpp:378
#12 0x00007fc2d46e44f9 in QMessageLogger::fatal
    (this=this@entry=0x7ffefd52ebe8, msg=msg@entry=0x7fc2d4a79db8 "ASSERT: \"%s\" in file %s, line %d")
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/global/qlogging.cpp:901
#13 0x00007fc2d46e34b8 in qt_assert (assertion=<optimized out>, file=<optimized out>, line=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/global/qassert.cpp:68
#14 0x00007fc2d86a735a in QChar::QChar (this=0x7ffefd52ec6c, rc=128514) at /usr/include/qt6/QtCore/qchar.h:79
#15 0x00007fc2d86a6f93 in Konsole::HTMLDecoder::decodeLine
--Type <RET> for more, q to quit, c to continue without paging--c
    (this=0x7ffefd52f0c0, characters=0x27d9120, count=2)
    at /home/akseli/Repositories/kde/src/konsole/src/decoders/HTMLDecoder.cpp:133
#16 0x00007fc2d870dcfb in Konsole::Screen::copyLineToStream
    (this=0x23107f0, line=2, start=6, count=2, decoder=0x7ffefd52f0c0, appendNewLine=false, isBlockSelectionMode=false, options=...) at /home/akseli/Repositories/kde/src/konsole/src/Screen.cpp:2242
#17 0x00007fc2d870cf6c in Konsole::Screen::writeToStream
    (this=0x23107f0, decoder=0x7ffefd52f0c0, startIndex=226, endIndex=227, options=...)
    at /home/akseli/Repositories/kde/src/konsole/src/Screen.cpp:2051
#18 0x00007fc2d870cdc0 in Konsole::Screen::text (this=0x23107f0, startIndex=226, endIndex=227, options=...)
    at /home/akseli/Repositories/kde/src/konsole/src/Screen.cpp:2018
#19 0x00007fc2d870cc6a in Konsole::Screen::selectedText (this=0x23107f0, options=...)
    at /home/akseli/Repositories/kde/src/konsole/src/Screen.cpp:1999
#20 0x00007fc2d871fd9f in Konsole::ScreenWindow::selectedText (this=0x1df9d50, options=...)
    at /home/akseli/Repositories/kde/src/konsole/src/ScreenWindow.cpp:120
#21 0x00007fc2d87ea748 in Konsole::TerminalDisplay::copyToX11Selection (this=0x2571980, useSavedText=false)
    at /home/akseli/Repositories/kde/src/konsole/src/terminalDisplay/TerminalDisplay.cpp:2387
#22 0x00007fc2d87e5f26 in Konsole::TerminalDisplay::mouseReleaseEvent (this=0x2571980, ev=0x7ffefd52faa0)
    at /home/akseli/Repositories/kde/src/konsole/src/terminalDisplay/TerminalDisplay.cpp:1527
#23 0x00007fc2d5c1e478 in QWidget::event (this=0x2571980, event=0x7ffefd52faa0)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/widgets/kernel/qwidget.cpp:9368
#24 0x00007fc2d87ecf3c in Konsole::TerminalDisplay::event (this=0x2571980, event=0x7ffefd52faa0)
    at /home/akseli/Repositories/kde/src/konsole/src/terminalDisplay/TerminalDisplay.cpp:2922
#25 0x00007fc2d5bc2b38 in QApplicationPrivate::notify_helper
    (this=this@entry=0x1e13410, receiver=receiver@entry=0x2571980, e=e@entry=0x7ffefd52faa0)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/widgets/kernel/qapplication.cpp:3290
#26 0x00007fc2d5bcca6b in QApplication::notify (this=<optimized out>, receiver=0x2571980, e=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/widgets/kernel/qapplication.cpp:2777
#27 0x00007fc2d47a0ba8 in QCoreApplication::notifyInternal2 (receiver=0x2571980, event=0x7ffefd52faa0)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/kernel/qcoreapplication.cpp:1118
#28 0x00007fc2d47a0dbd in QCoreApplication::sendSpontaneousEvent
    (receiver=<optimized out>, event=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/kernel/qcoreapplication.cpp:1550
#29 0x00007fc2d5bcb253 in QApplicationPrivate::sendMouseEvent
    (receiver=receiver@entry=0x2571980, event=event@entry=0x7ffefd52faa0, alienWidget=<optimized out>, nativeWidget=0x22608d0, buttonDown=buttonDown@entry=0x7fc2d61b26e0 <qt_button_down>, lastMouseReceiver=..., spontaneous=true, onlyDispatchEnterLeave=false)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/widgets/kernel/qapplication.cpp:2361
#30 0x00007fc2d5c32006 in QWidgetWindow::handleMouseEvent (this=0x2187760, event=event@entry=0x7ffefd52fd60)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/widgets/kernel/qwidgetwindow.cpp:627
#31 0x00007fc2d5c34f30 in QWidgetWindow::event (this=0x2187760, event=0x7ffefd52fd60)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/widgets/kernel/qwidgetwindow.cpp:241
#32 0x00007fc2d5bc2b38 in QApplicationPrivate::notify_helper
    (this=<optimized out>, receiver=0x2187760, e=0x7ffefd52fd60)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/widgets/kernel/qapplication.cpp:3290
#33 0x00007fc2d47a0ba8 in QCoreApplication::notifyInternal2 (receiver=0x2187760, event=0x7ffefd52fd60)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/kernel/qcoreapplication.cpp:1118
#34 0x00007fc2d47a0dbd in QCoreApplication::sendSpontaneousEvent
    (receiver=<optimized out>, event=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/kernel/qcoreapplication.cpp:1550
#35 0x00007fc2d5209127 in QGuiApplicationPrivate::processMouseEvent (e=0x7fc2b4001550)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/gui/kernel/qguiapplication.cpp:2315
#36 0x00007fc2d5267c1c in QWindowSystemInterface::sendWindowSystemEvents (flags=...)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/gui/kernel/qwindowsysteminterface.cpp:1109
#37 0x00007fc2d573ff14 in userEventSourceDispatch (source=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/gui/platform/unix/qeventdispatcher_glib.cpp:38
#38 0x00007fc2d07c2e5c in g_main_dispatch (context=0x7fc2bc000ef0) at ../glib/gmain.c:3476
#39 g_main_context_dispatch_unlocked (context=0x7fc2bc000ef0) at ../glib/gmain.c:4284
#40 0x00007fc2d081df18 in g_main_context_iterate_unlocked.isra.0
    (context=context@entry=0x7fc2bc000ef0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4349
#41 0x00007fc2d07c0ad3 in g_main_context_iteration (context=0x7fc2bc000ef0, may_block=1)
    at ../glib/gmain.c:4414
#42 0x00007fc2d4a4096f in QEventDispatcherGlib::processEvents (this=0x1e25180, flags=...)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/kernel/qeventdispatcher_glib.cpp:393
#43 0x00007fc2d47ad9bb in QEventLoop::exec (this=this@entry=0x7ffefd530190, flags=..., flags@entry=...)
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/global/qflags.h:34
#44 0x00007fc2d47a97bd in QCoreApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/global/qflags.h:74
#45 0x00000000004053eb in main (argc=1, argv=0x7ffefd5306b8)
    at /home/akseli/Repositories/kde/src/konsole/src/main.cpp:233
Comment 6 Bug Janitor Service 2024-01-23 12:51:05 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/konsole/-/merge_requests/949
Comment 7 Amir Khan 2024-01-23 15:34:08 UTC
Confirmed that I have reproduced this:

1. Paste and emoji into Konsole using emoji selector
2. Use mouse to select emoji in Konsole
3. Konsole crashes immediately.

System used:
KDE Neon Unstable (fully updated 23/01/24 afternoon GMT zone)
KDE Plasma Version 6.0.80
KDE Frameworks Version 5.249.0
Qt Version 6.6.1
Kernel Version 6.5.0-14-generic (64-bit)

Above running in a Gnome Boxes VM in X11 session on Ubuntu 22.04 host.
Comment 8 Oded Arbel 2024-02-12 09:50:35 UTC
I can also reproduce by clicking the "Edit" menu then "Select All". The backtrace looks a bit different but all roads lead to `Konsole::Screen::copyLineToStream`:

---8<---
#15 0x00007f13ab4a9261 in qt_assert (assertion=<optimized out>, file=<optimized out>, line=<optimized out>) at ./src/corelib/global/qassert.cpp:68
#16 0x00007f13aca875d7 in ?? () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#17 0x00007f13aca8f0f3 in ?? () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#18 0x00007f13acac7736 in Konsole::Screen::copyLineToStream(int, int, int, Konsole::TerminalCharacterDecoder*, bool, bool, QFlags<Konsole::Screen::DecodingOption>) const () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#19 0x00007f13acac7d83 in Konsole::Screen::writeToStream(Konsole::TerminalCharacterDecoder*, int, int, QFlags<Konsole::Screen::DecodingOption>) const () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#20 0x00007f13acacb634 in Konsole::Screen::text(int, int, QFlags<Konsole::Screen::DecodingOption>) const () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#21 0x00007f13acacb7da in Konsole::Screen::selectedText(QFlags<Konsole::Screen::DecodingOption>) const () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#22 0x00007f13acacd066 in Konsole::ScreenWindow::selectedText(QFlags<Konsole::Screen::DecodingOption>) const () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#23 0x00007f13acb3e621 in Konsole::TerminalDisplay::copyToX11Selection(bool) () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#24 0x00007f13acb78c71 in Konsole::SessionController::selectAll() () from /lib/x86_64-linux-gnu/libkonsoleprivate.so.24.01.95
#25 0x00007f13ab4287ae in QtPrivate::QSlotObjectBase::call (a=<optimized out>, r=<optimized out>, this=<optimized out>, this=<optimized out>, r=<optimized out>, a=<optimized out>) at ./src/corelib/kernel/qobjectdefs_impl.h:433
#26 doActivate<false> (sender=0x55b917f598f0, signal_index=7, argv=0x7ffc945a32e0) at ./src/corelib/kernel/qobject.cpp:4021
#27 0x00007f13abc3b956 in QAction::triggered (this=this@entry=0x55b917f598f0, _t1=<optimized out>) at ./obj-x86_64-linux-gnu/src/gui/Gui_autogen/include/moc_qaction.cpp:642
#28 0x00007f13abc3f6b4 in QAction::activate (this=0x55b917f598f0, event=<optimized out>) at ./src/gui/kernel/qaction.cpp:1102
#29 0x00007f13ac4ea96e in QMenuPrivate::activateCausedStack (this=0x55b917c0c660, causedStack=..., action=0x55b917f598f0, action_e=QAction::Trigger, self=<optimized out>) at ./src/widgets/widgets/qmenu.cpp:1413
#30 0x00007f13ac4f2bd9 in QMenuPrivate::activateAction (this=0x55b917c0c660, action=0x55b917f598f0, action_e=QAction::Trigger, self=<optimized out>) at ./src/widgets/widgets/qmenu.cpp:1495
---8<---
Comment 9 Kurt Hindenburg 2024-02-23 21:32:23 UTC
Git commit d09b394c228e9c9d6da3c046d5b44b2193819f43 by Kurt Hindenburg, on behalf of Luis Javier Merino Morán.
Committed on 23/02/2024 at 19:37.
Pushed by hindenburg into branch 'master'.

Support non-BMP codepoints in HTMLDecoder

HTMLDecoder, used for encoding as HTML, didn't support characters
outside the Unicode Basic Multilingual Plane, causing mojibake on Qt 5,
and assert failures in Qt 6.

M  +1    -1    src/decoders/HTMLDecoder.cpp

https://invent.kde.org/utilities/konsole/-/commit/d09b394c228e9c9d6da3c046d5b44b2193819f43