From 823714cf66c887886fb58a21c016f0d58acb1047 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Feb 2020 16:56:29 +0100 Subject: [PATCH 1/2] filechooser: Fix crash when file has no content-type This might happen for slow filesystems where a fast-content-type might be provided instead. Don't try to manipulate that content_type if it's NULL, otherwise we'll either throw warnings (at best) or crash (at worse). Conflicts: gtk/gtkfilechooserwidget.c --- gtk/gtkfilechooserwidget.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 9460663468..adee2ab5d8 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -4599,6 +4599,9 @@ get_type_information (GtkFileChooserWidget *impl, GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl); content_type = g_file_info_get_content_type (info); + if (!content_type) + goto end; + switch (priv->type_format) { case TYPE_FORMAT_MIME: @@ -4616,6 +4619,7 @@ get_type_information (GtkFileChooserWidget *impl, g_assert_not_reached (); } +end: return g_strdup (""); } From 8cb45cdeae7ae981447d80368a4f5a433f3c2d36 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Feb 2020 16:59:19 +0100 Subject: [PATCH 2/2] filechooser: Fallback if content-type unavailable Fallback to fast-content-type if the content-type attribute isn't available, as is the case for most remote filesystems. Closes: #2482 --- gtk/gtkfilechooserwidget.c | 4 +++- gtk/gtkfilesystemmodel.c | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index adee2ab5d8..4b5db9e972 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -393,7 +393,7 @@ static guint signals[LAST_SIGNAL] = { 0 }; #define MODEL_ATTRIBUTES "standard::name,standard::type,standard::display-name," \ "standard::is-hidden,standard::is-backup,standard::size," \ - "standard::content-type,time::modified,time::access," \ + "standard::content-type,standard::fast-content-type,time::modified,time::access," \ "access::can-rename,access::can-delete,access::can-trash," \ "standard::target-uri" enum { @@ -4599,6 +4599,8 @@ get_type_information (GtkFileChooserWidget *impl, GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl); content_type = g_file_info_get_content_type (info); + if (!content_type) + content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE); if (!content_type) goto end; diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c index e7c4bd8bbb..eeab450301 100644 --- a/gtk/gtkfilesystemmodel.c +++ b/gtk/gtkfilesystemmodel.c @@ -397,6 +397,10 @@ node_should_be_filtered_out (GtkFileSystemModel *model, guint id) if (required & GTK_FILE_FILTER_MIME_TYPE) { const char *s = g_file_info_get_content_type (node->info); + + if (!s) + s = g_file_info_get_attribute_string (node->info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE); + if (s) { mime_type = g_content_type_get_mime_type (s);