Crash caused by attempting to decode invalid unicode characters
wxHexEditor crashes with a failed assertion when it tries to decode binary data that contains invalid Unicode characters.
Error message printed on the standard output and error message dialogue:
../src/common/strconv.cpp(1188): assert "Assert failure" failed in FromWChar(): trying to encode undefined Unicode character
This 5 bytes file triggers the issue: wxHexEditor_crash.txt
Used version: 0.24+repack-1 obtained from https://packages.ubuntu.com/eoan/wxhexeditor
OS: Kubuntu 19.10
Unfortunately, I wasn’t able to compile the latest master branch commit, because of #150…
I tried to open that text file and... It doesn't generate any assertions here.
What is your distro? I don't understand why you can't compile at all. If you give your distros ISO link, I try to setup and compile wxHexEditor on VM.
Distro: Kubuntu 19.10. Download web page, Direct ISO link
I dug a bit more and ran wxHexEditor under gdb. I loaded the file and that’s the stack trace generated by gdb:
#0 0x00007ffff6d423cb in raise (sig=<optimized out>) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007ffff77563bd in wxGUIAppTraits::ShowAssertDialog(wxString const&) () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#2 0x00007ffff7206b57 in () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#3 0x00007ffff72097fc in wxAppConsoleBase::OnAssertFailure(wchar_t const*, int, wchar_t const*, wchar_t const*, wchar_t const*) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#4 0x00007ffff7722874 in wxApp::OnAssertFailure(wchar_t const*, int, wchar_t const*, wchar_t const*, wchar_t const*) () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#5 0x00007ffff7209adf in () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#6 0x00007ffff7208dd9 in wxOnAssert(char const*, int, char const*, char const*, wchar_t const*) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#7 0x00007ffff72bd500 in wxMBConvStrictUTF8::FromWChar(char*, unsigned long, wchar_t const*, unsigned long) const () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#8 0x00007ffff72cb99c in wxString::AsChar(wxMBConv const&) const () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#9 0x00007ffff7861991 in wxCairoContext::GetTextExtent(wxString const&, double*, double*, double*, double*) const () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#10 0x00007ffff78725b8 in wxGraphicsContext::DoDrawFilledText(wxString const&, double, double, wxGraphicsBrush const&) () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#11 0x00007ffff7824774 in wxGCDCImpl::DoDrawText(wxString const&, int, int) () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#12 0x000055555565ef2b in ()
#13 0x0000555555654c66 in ()
#14 0x0000555555649ef7 in ()
#15 0x0000555555631adb in ()
#16 0x0000555555634d5b in ()
#17 0x000055555566e88d in ()
#18 0x00005555556724f3 in ()
#19 0x00007ffff738d671 in wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#20 0x00007ffff738da0a in wxEvtHandler::SearchDynamicEventTable(wxEvent&) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#21 0x00007ffff738daa4 in wxEvtHandler::TryHereOnly(wxEvent&) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#22 0x00007ffff738d933 in wxEvtHandler::DoTryChain(wxEvent&) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#23 0x00007ffff738dc01 in wxEvtHandler::ProcessEvent(wxEvent&) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#24 0x00007ffff7922f8a in wxWindowBase::TryAfter(wxEvent&) () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#25 0x00007ffff714e0c1 in wxAuiToolBar::OnLeftUp(wxMouseEvent&) () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_aui-3.0.so.0
#26 0x00007ffff738d671 in wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#27 0x00007ffff738d773 in wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#28 0x00007ffff738dad0 in wxEvtHandler::TryHereOnly(wxEvent&) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#29 0x00007ffff738db5b in wxEvtHandler::ProcessEventLocally(wxEvent&) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#30 0x00007ffff738dc01 in wxEvtHandler::ProcessEvent(wxEvent&) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#31 0x00007ffff738d98b in wxEvtHandler::SafelyProcessEvent(wxEvent&) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#32 0x00007ffff775f563 in () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#33 0x00007ffff680f70b in () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#34 0x00007ffff61466e2 in g_closure_invoke () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#35 0x00007ffff615a544 in () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#36 0x00007ffff616299e in g_signal_emit_valist () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#37 0x00007ffff61639b3 in g_signal_emit () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#38 0x00007ffff67b9e53 in () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#39 0x00007ffff66759d8 in () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#40 0x00007ffff6677c2b in gtk_main_do_event () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#41 0x00007ffff6361f19 in () at /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
#42 0x00007ffff6394ff6 in () at /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
#43 0x00007ffff605b84d in g_main_context_dispatch () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#44 0x00007ffff605bad0 in () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#45 0x00007ffff605bdc3 in g_main_loop_run () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#46 0x00007ffff6676c2d in gtk_main () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#47 0x00007ffff773e5e5 in wxGUIEventLoop::DoRun() () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#48 0x00007ffff7241d51 in wxEventLoopBase::Run() () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#49 0x00007ffff72093ea in wxAppConsoleBase::MainLoop() () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#50 0x00007ffff729574d in wxEntry(int&, wchar_t**) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#51 0x00005555555ce0e6 in ()
#52 0x00007ffff6b631e3 in __libc_start_main (main=0x5555555ce0d0, argc=1, argv=0x7fffffffde28, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffde18) at ../csu/libc-start.c:308
#53 0x00005555555ce76e in ()
This looks like it might be a bug in wxWidgets or your usage of some API violates some preconditions the API assumes to be true (like not passing invalid bytes into the Unicode renderer).
I installed and find that c++ compiler complain about absence of -lgomp while libgomp1 is already installed. Looks like ubuntu distro's error. Nothing to do here. You can remove -fopenmp and -lgomp flags inside Makefile and retry.
Ok, git master does not crash on loading the file.
- But it crashes with a segmentation fault on exit, even if no file was loaded.
- If I resize the main window, It prints a whole bunch of failed assertions inside GLib-GObject and GTK before closing, and then segmentation faults.
This is the Makefile diff:
diff --git a/Makefile b/Makefile
index a6b5384..459a1ec 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,6 @@ WXCONFIG ?= wx-config
HOST=
WXCXXFLAGS= `$(WXCONFIG) --cxxflags` -Iudis86 -Imhash/include -MMD -Wall -O2 -DNDEBUG
WXLDFLAGS = `$(WXCONFIG) --libs` `$(WXCONFIG) --libs aui` `$(WXCONFIG) --libs core`
-WXCXXFLAGS += -fopenmp
#add this ldflags for WinConsole "-Wl,--subsystem,console -mconsole" for win-debug
#LDFLAGS += -Wl,--subsystem,console -mconsole
RC = `$(WXCONFIG) --rescomp`
@@ -21,7 +20,7 @@ SOURCES= src/HexEditorGui.cpp \
src/HexEditorCtrl/wxHexCtrl/Tag.cpp\
src/HexEditorCtrl/HexEditorCtrlGui.cpp\
src/HexEditorFrame.cpp
-LIBS = udis86/libudis86/.libs/libudis86.a mhash/lib/.libs/libmhash.a -lgomp
+LIBS = udis86/libudis86/.libs/libudis86.a mhash/lib/.libs/libmhash.a
OBJECTS=$(SOURCES:.cpp=.o)
DEPENDS=$(OBJECTS:.o=.d)
LANGUAGEDIRS=`ls -l ./locale | grep ^d | sed s/.*\ //g;`
This is the backtrace I get on exit, if it crashes:
#0 0x00005555556837fd in HexEditorFrame::~HexEditorFrame() ()
#1 0x000055555568393d in HexEditorFrame::~HexEditorFrame() ()
#2 0x00007ffff74785a7 in wxAppConsoleBase::DeletePendingObjects() () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#3 0x00007ffff7478629 in wxAppConsoleBase::ProcessIdle() () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#4 0x00007ffff7a68f78 in wxAppBase::ProcessIdle() () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#5 0x00007ffff7993605 in wxApp::DoIdle() () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#6 0x00007ffff7993707 in () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#7 0x00007ffff630a71e in g_main_context_dispatch () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#8 0x00007ffff630aad0 in () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#9 0x00007ffff630adc3 in g_main_loop_run () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#10 0x00007ffff6925c2d in gtk_main () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#11 0x00007ffff79b15e5 in wxGUIEventLoop::DoRun() () at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#12 0x00007ffff74b6d51 in wxEventLoopBase::Run() () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#13 0x00007ffff747e3ea in wxAppConsoleBase::MainLoop() () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#14 0x00007ffff750a74d in wxEntry(int&, wchar_t**) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#15 0x00005555555db12c in main ()
The printed assertion failures. These are only printed, if I resize the main window.
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_queue_draw_area: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_unrealize: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_unset_state_flags: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_add_tick_callback: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): GLib-GObject-WARNING **: 13:08:44.333: ../../../gobject/gsignal.c:3189: signal id '48' is invalid for instance '0x55d5cfa023a0'
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_get_screen: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_get_frame_clock: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): GLib-GObject-WARNING **: 13:08:44.333: ../../../gobject/gsignal.c:3189: signal id '49' is invalid for instance '0x55d5cfa023a0'
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_get_frame_clock: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): GLib-GObject-WARNING **: 13:08:44.333: ../../../gobject/gsignal.c:3189: signal id '49' is invalid for instance '0x55d5cfa007a0'
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_set_parent_window: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_queue_resize: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_unrealize: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): GLib-GObject-WARNING **: 13:08:44.333: ../../../gobject/gsignal.c:3189: signal id '38' is invalid for instance '0x55d5cfa023a0'
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_get_style_context: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_style_context_set_parent: assertion 'GTK_IS_STYLE_CONTEXT (context)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_get_realized: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: accel_widget_weak_ref_cb: assertion 'GTK_IS_WIDGET (accel_label->priv->accel_widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_unrealize: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): GLib-GObject-WARNING **: 13:08:44.333: ../../../gobject/gsignal.c:3189: signal id '38' is invalid for instance '0x55d5cfa023a0'
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_widget_has_grab: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.333: gtk_container_remove: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): GLib-GObject-WARNING **: 13:08:44.333: ../../../gobject/gsignal.c:3189: signal id '38' is invalid for instance '0x55d5cf8442c0'
(wxHexEditor:12132): Gtk-WARNING **: 13:08:44.333: mnemonic "n" wasn't removed for widget (0x55d5cf9ef1c0)
(wxHexEditor:12132): Gtk-WARNING **: 13:08:44.333: mnemonic "a" wasn't removed for widget (0x55d5cf9efb70)
(wxHexEditor:12132): Gtk-WARNING **: 13:08:44.334: mnemonic "odiaeresis" wasn't removed for widget (0x55d5cf9ef3b0)
(wxHexEditor:12132): Gtk-WARNING **: 13:08:44.334: mnemonic "s" wasn't removed for widget (0x55d5cf9ef980)
(wxHexEditor:12132): Gtk-WARNING **: 13:08:44.334: mnemonic "e" wasn't removed for widget (0x55d5cfa005b0)
(wxHexEditor:12132): Gtk-WARNING **: 13:08:44.334: mnemonic "r" wasn't removed for widget (0x55d5cf9ef790)
(wxHexEditor:12132): Gtk-WARNING **: 13:08:44.334: mnemonic "c" wasn't removed for widget (0x55d5cf9efd60)
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_has_grab: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_get_parent: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_has_default: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_get_receives_default: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_get_display: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gdk-CRITICAL **: 13:08:44.334: gdk_display_get_device_manager: assertion 'GDK_IS_DISPLAY (display)' failed
(wxHexEditor:12132): Gdk-CRITICAL **: 13:08:44.334: gdk_device_manager_list_devices: assertion 'GDK_IS_DEVICE_MANAGER (device_manager)' failed
(wxHexEditor:12132): Gdk-CRITICAL **: 13:08:44.334: gdk_device_manager_list_devices: assertion 'GDK_IS_DEVICE_MANAGER (device_manager)' failed
(wxHexEditor:12132): Gdk-CRITICAL **: 13:08:44.334: gdk_device_manager_list_devices: assertion 'GDK_IS_DEVICE_MANAGER (device_manager)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_has_default: assertion 'GTK_IS_WIDGET (widget)' failed
(wxHexEditor:12132): Gtk-CRITICAL **: 13:08:44.334: gtk_widget_get_accessible: assertion 'GTK_IS_WIDGET (widget)' failed
If I keep the default window size (see screenshot below), these assertions don’t trigger.

I tried running valgrind on the binary.
Just opening and closing wxHexEditor:
$ valgrind --leak-check=full -s --track-origins=yes --log-file="wxHex_Valgrind.log.txt" ./wxHexEditor: wxHex_Valgrind.log.txt
$ valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file="wxHex_Valgrind.log.txt" ./wxHexEditor: wxHex_Valgrind_full.zip (Beware: 14 MiB uncompressed size)
Resizing the GUI, loading the 5 bytes file posted in the original issue, marked some bytes, then closed the editor:
$ valgrind --leak-check=full -s --track-origins=yes --log-file="wxHex_Valgrind.log.txt" ./wxHexEditor: wxHex_Valgrind.log.txt
Yup. I am aware from that. I think, SegFault on exit might due wxMemoryBuffer copy_maker somehow. Also have some "size" issues recently. But GTK assertions are with us for a long time. Debugger doesn't give assertions on those here, somehow. Will look it what is wrong soon.