check if string is valid UTF-8 before collating
[claws.git] / src / common / utils.c
index b8cf669eeced993912d9acd96d65fa9c4523276c..cd01eb530770ce800a6e6e5fa65b63125d090731 100644 (file)
@@ -452,6 +452,14 @@ gint subject_compare_for_sort(const gchar *s1, const gchar *s2)
        trim_subject_for_sort(str1);
        trim_subject_for_sort(str2);
 
+       if (!g_utf8_validate(str1, -1, NULL)) {
+               g_warning("message subject \"%s\" failed UTF-8 validation", str1);
+               return 0;
+       } else if (!g_utf8_validate(str2, -1, NULL)) {
+               g_warning("message subject \"%s\" failed UTF-8 validation", str2);
+               return 0;
+       }
+
        return g_utf8_collate(str1, str2);
 }