#169 geeqie crashes on invalid filename encoding

v1.0
open
GUI (73)
5
2011-06-25
2011-06-25
No

Geeqie 1.0 core dumps when opening a directory with non-utf8 filenames. It generates traceback like that:

(gdb) bt
#0 0x0000000803800f34 in strxfrm () from /lib/libc.so.7
#1 0x0000000802c604d8 in g_utf8_collate_key () from /usr/local/lib/libglib-2.0.so.0
#2 0x000000000045ee62 in file_data_set_collate_keys (fd=0x806cf9240) at filedata.c:238
#3 0x000000000045f14d in file_data_set_path (fd=0x806cf9240, path=0x806cf8310 "/home/novel/TRIAGRUTRIKA - �.�.�.���߿� (2011)")
at filedata.c:301
#4 0x000000000045f71c in file_data_new (path_utf8=0x806cf8310 "/home/novel/TRIAGRUTRIKA - �.�.�.���߿� (2011)", st=0x7fffffffda50,
check_sidecars=0, basename_hash=0x0) at filedata.c:441
#5 0x000000000045fb38 in file_data_new_local (path=0x806aa69c0 "/home/novel/TRIAGRUTRIKA - �.�.�.���߿� (2011)", st=0x7fffffffda50,
check_sidecars=0, basename_hash=0x0) at filedata.c:589
#6 0x0000000000460d13 in filelist_read_real (dir_fd=0x806c80ac0, files=0x0, dirs=0x806b77e08, follow_symlinks=1) at filedata.c:1073
#7 0x0000000000460e4a in filelist_read (dir_fd=0x806c80ac0, files=0x0, dirs=0x806b77e08) at filedata.c:1107
#8 0x00000000004d6d0c in vdlist_populate (vd=0x806a5a900, clear=1) at view_dir_list.c:154
#9 0x00000000004d735d in vdlist_set_fd (vd=0x806a5a900, dir_fd=0x806c80ac0) at view_dir_list.c:320
#10 0x00000000004d4729 in vd_set_fd (vd=0x806a5a900, dir_fd=0x806c80ac0) at view_dir.c:159
#11 0x0000000000478051 in layout_sync_path (lw=0x806a9d800) at layout.c:843
#12 0x000000000047831d in layout_set_fd (lw=0x806a9d800, fd=0x806c80ac0) at layout.c:914
#13 0x00000000004780ca in layout_set_path (lw=0x806a9d800, path=0x806b35380 "/home/novel") at layout.c:855
#14 0x000000000047c382 in layout_new_from_config (attribute_names=0x7fffffffe070, attribute_values=0x7fffffffdf50, use_commandline=1)
at layout.c:2426
#15 0x00000000004bf4e4 in options_parse_toplevel (parser_data=0x806aa9c70, context=0x806a8a740, element_name=0x806b1ed00 "layout",
attribute_names=0x7fffffffe070, attribute_values=0x7fffffffdf50, data=0x0, error=0x7fffffffe1a0) at rcfile.c:1102
#16 0x00000000004bf700 in start_element (context=0x806a8a740, element_name=0x806b1ed00 "layout", attribute_names=0x7fffffffe070,
attribute_values=0x7fffffffdf50, user_data=0x806aa9c70, error=0x7fffffffe1a0) at rcfile.c:1167
#17 0x0000000802c3636a in g_markup_collect_attributes () from /usr/local/lib/libglib-2.0.so.0
#18 0x0000000802c370aa in g_markup_parse_context_parse () from /usr/local/lib/libglib-2.0.so.0
#19 0x00000000004bf861 in load_config_from_buf (
buf=0x806b2c000 "<!--\n", '#' <repeats 70 times>, "\n#", ' ' <repeats 25 times>, "Geeqie config file version 1.0 #\n", '#' <repeats 53 times>..., size=13060, startup=1) at rcfile.c:1212
#20 0x00000000004bf929 in load_config_from_file (utf8_path=0x806aa6980 "/home/novel/.config/geeqie/geeqierc.xml", startup=1)
at rcfile.c:1234
#21 0x000000000048f38d in load_options (options=0x806a69c00) at options.c:258
#22 0x000000000048854e in main (argc=2, argv=0x7fffffffe410) at main.c:824
(gdb)

It seems to happen because g_utf8_collate_key() always expects a valid UTF-8. In the attached diff I check if the file name if a valid UTF-8 string, if it's not convert it using g_filename_display_name(). It fixes a problem for me.

Discussion

  • Vladimir Nadvornik

    I am afraid this patch causes a leak and maybe other problems. For a correct fix we have to review FileData structure and separate file access and display purpose variables.

    For now I have commited a simpler fix which should prevent the crash above, git 27bec4237fa34883854d8c83ce1484fcc0aef165