deluge-gtk crashes on start
glib-2.70.2; gtk+-3.24.31
Gentoo Linux amd64
How to reproduce: Start deluge-gtk
$ deluge-gtk
Segmentation fault
What happens: Program crashes with segmentation fault
deluge-2.0.5-r1; python-3.9.9-r1
As I was setting up nextcloud-client, deluge-gtk crashed, and would not run anymore, crashing on start with segfault.
deluge-gtk[10443]: segfault at 0 ip 00007f7f6352bfac sp 00007fff5c3d0fd8 error 4 in libglib-2.0.so.0.7000.2[7f7f634bd000+8f000]
I built gtk+ and glib with debug symbols, here's python backtrace: deluge.trace.txt
Thread 1 "deluge-gtk" received signal SIGSEGV, Segmentation fault.
0x00007ffff50195a7 in fast_validate (str=0x0) at ../glib-2.70.2/glib/gutf8.c:1498
1498 for (p = str; *p; p++)
(gdb) bt
#0 0x00007ffff50195a7 in fast_validate (str=0x0) at ../glib-2.70.2/glib/gutf8.c:1498
#1 0x00007ffff5019871 in g_utf8_validate (str=0x0, max_len=-1, end=0x0)
at ../glib-2.70.2/glib/gutf8.c:1681
#2 0x00007ffff364e336 in on_bookmark_query_info_complete
(source=0x5555566c32d0 [GDummyFile], result=<optimized out>, data=0x555556514780)
at /usr/src/debug/x11-libs/gtk+-3.24.31/gtk+-3.24.31/gtk/gtkplacessidebar.c:869
#3 0x00007ffff4cf7c73 in g_task_return_now (task=0x555556447600 [GTask])
at ../glib-2.70.2/gio/gtask.c:1219
#4 0x00007ffff4cf7cc8 in complete_in_idle_cb (task=0x555556447600)
at ../glib-2.70.2/gio/gtask.c:1233
#5 0x00007ffff4fd6a95 in g_idle_dispatch
(source=0x7fffe4010f90, callback=0x7ffff4cf7cb0 <complete_in_idle_cb>, user_data=0x555556447600) at ../glib-2.70.2/glib/gmain.c:5897
#6 0x00007ffff4fd3779 in g_main_dispatch (context=0x555555d0aa60)
at ../glib-2.70.2/glib/gmain.c:3381
#7 0x00007ffff4fd4798 in g_main_context_dispatch (context=0x555555d0aa60)
at ../glib-2.70.2/glib/gmain.c:4099
#8 0x00007ffff4fd499a in g_main_context_iterate
(context=0x555555d0aa60, block=1, dispatch=1, self=0x55555613c8a0)
at ../glib-2.70.2/glib/gmain.c:4175
#9 0x00007ffff4fd4a72 in g_main_context_iteration
(context=0x555555d0aa60, may_block=1) at ../glib-2.70.2/glib/gmain.c:4240
#10 0x00007ffff360c495 in gtk_main_iteration ()
at /usr/src/debug/x11-libs/gtk+-3.24.31/gtk+-3.24.31/gtk/gtkmain.c:1433
#11 0x00007ffff609ce3d in () at /usr/lib64/libffi.so.7
g_file_get_basename() returns NULL for GFile *root, which refers to:
(gdb) print g_file_get_parse_name(root)
[Thread 0x7fffeef47640 (LWP 24453) exited]
$3 = 0x555556801f80 "file:///drv/secondary/%NEXTCLOUD"
I'm not sure why deluge looks at this unrelated directory. My guess is nextcloud-client created XDG entry for "/drv/secondary/%NEXTCLOUD", so gtk+ tries to do something with it, does not check output for NULL-value and crashes in glib.
This is very similar to #2385 (moved) , even same code, just in a different place. In gtk/gtkplacessidebar.c:
867 /* Don't add non-UTF-8 bookmarks */
868 bookmark_name = g_file_get_basename (root);
869 if (!g_utf8_validate (bookmark_name, -1, NULL))
So it probably needs to be sanitized in gtk+. But it seems like failing to return basename if there's a percent sign in the last component is also a bug. As far as I know, % is a perfectly legal filename character for ext4 filesystem. And can be used unescaped with URL, according to the spec I looked at. Using "file:///drv/secondary/%NEXTCLOUD" to browse local files in Firefox works just fine too.