mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 23:13:40 +02:00
gcontenttype: Make filename valid utf-8 string before processing
The `g_content_type_guess_for_tree` function segfaults currently when processing filenames that are not valid unicode strings. Let's use the `g_filename_to_utf8` and `g_utf8_make_valid` functions before other processing to prevent that. Let's also add a test for it to avoid this in future. Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/3168
This commit is contained in:
committed by
Philip Withnall
parent
b50a8a69d9
commit
30e102518a
@@ -1274,7 +1274,7 @@ component_match (Enumerator *e,
|
||||
gint depth,
|
||||
const gchar *name)
|
||||
{
|
||||
gchar *case_folded, *key;
|
||||
gchar *case_folded, *key, *utf8_name;
|
||||
gboolean found;
|
||||
|
||||
if (strcmp (name, e->components[depth]) == 0)
|
||||
@@ -1283,11 +1283,16 @@ component_match (Enumerator *e,
|
||||
if (!e->ignore_case)
|
||||
return FALSE;
|
||||
|
||||
case_folded = g_utf8_casefold (name, -1);
|
||||
utf8_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
|
||||
if (utf8_name == NULL)
|
||||
utf8_name = g_utf8_make_valid (name, -1);
|
||||
|
||||
case_folded = g_utf8_casefold (utf8_name, -1);
|
||||
key = g_utf8_collate_key (case_folded, -1);
|
||||
|
||||
found = strcmp (key, e->case_components[depth]) == 0;
|
||||
|
||||
g_free (utf8_name);
|
||||
g_free (case_folded);
|
||||
g_free (key);
|
||||
|
||||
|
Reference in New Issue
Block a user