[evolution/gnome-3-30] I#282 - Do not preview pipe-s in GtkFileChooser
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/gnome-3-30] I#282 - Do not preview pipe-s in GtkFileChooser
- Date: Wed, 16 Jan 2019 15:00:43 +0000 (UTC)
commit 22040cf95a257c28d3c697bd0cd72d2414b46453
Author: Milan Crha <mcrha redhat com>
Date: Wed Jan 16 16:01:01 2019 +0100
I#282 - Do not preview pipe-s in GtkFileChooser
Closes https://gitlab.gnome.org/GNOME/evolution/issues/282
.../gui/contact-editor/e-contact-editor.c | 11 +++++---
src/e-util/e-attachment-store.c | 4 ++-
src/e-util/e-image-chooser-dialog.c | 12 ++++++++-
src/e-util/e-misc-utils.c | 29 ++++++++++++++++++++++
src/e-util/e-misc-utils.h | 1 +
src/plugins/face/face.c | 3 ++-
6 files changed, 54 insertions(+), 6 deletions(-)
---
diff --git a/src/addressbook/gui/contact-editor/e-contact-editor.c
b/src/addressbook/gui/contact-editor/e-contact-editor.c
index f506bd514d..c5bea88abf 100644
--- a/src/addressbook/gui/contact-editor/e-contact-editor.c
+++ b/src/addressbook/gui/contact-editor/e-contact-editor.c
@@ -4279,16 +4279,21 @@ update_preview_cb (GtkFileChooser *file_chooser,
gpointer data)
{
GtkWidget *preview;
- gchar *filename = NULL;
+ gchar *filename;
GdkPixbuf *pixbuf;
- gtk_file_chooser_set_preview_widget_active (file_chooser, TRUE);
preview = GTK_WIDGET (data);
filename = gtk_file_chooser_get_preview_filename (file_chooser);
- if (filename == NULL)
+ if (!e_util_can_preview_filename (filename)) {
+ gtk_file_chooser_set_preview_widget_active (file_chooser, FALSE);
+ g_free (filename);
return;
+ }
+
+ gtk_file_chooser_set_preview_widget_active (file_chooser, TRUE);
pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
+
if (!pixbuf) {
gchar *alternate_file;
alternate_file = e_icon_factory_get_icon_filename (
diff --git a/src/e-util/e-attachment-store.c b/src/e-util/e-attachment-store.c
index 226cbb503c..587b5b7a9a 100644
--- a/src/e-util/e-attachment-store.c
+++ b/src/e-util/e-attachment-store.c
@@ -606,8 +606,10 @@ update_preview_cb (GtkFileChooser *file_chooser,
gtk_image_clear (GTK_IMAGE (data));
preview = GTK_WIDGET (data);
filename = gtk_file_chooser_get_preview_filename (file_chooser);
- if (filename == NULL)
+ if (!e_util_can_preview_filename (filename)) {
+ g_free (filename);
return;
+ }
pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
g_free (filename);
diff --git a/src/e-util/e-image-chooser-dialog.c b/src/e-util/e-image-chooser-dialog.c
index 56d8f7de88..f501a473bd 100644
--- a/src/e-util/e-image-chooser-dialog.c
+++ b/src/e-util/e-image-chooser-dialog.c
@@ -22,6 +22,7 @@
#include <glib/gi18n-lib.h>
+#include "e-misc-utils.h"
#include "e-image-chooser-dialog.h"
#define E_IMAGE_CHOOSER_DIALOG_GET_PRIVATE(obj) \
@@ -104,6 +105,7 @@ image_chooser_dialog_update_preview (GtkFileChooser *file_chooser)
GtkWidget *preview_widget;
GFile *preview_file;
Context *context;
+ gchar *filename;
priv = E_IMAGE_CHOOSER_DIALOG_GET_PRIVATE (file_chooser);
preview_file = gtk_file_chooser_get_preview_file (file_chooser);
@@ -118,9 +120,17 @@ image_chooser_dialog_update_preview (GtkFileChooser *file_chooser)
gtk_image_clear (GTK_IMAGE (preview_widget));
gtk_file_chooser_set_preview_widget_active (file_chooser, FALSE);
- if (preview_file == NULL)
+ if (!preview_file)
return;
+ filename = gtk_file_chooser_get_preview_filename (file_chooser);
+ if (!e_util_can_preview_filename (filename)) {
+ g_free (filename);
+ g_object_unref (preview_file);
+ return;
+ }
+ g_free (filename);
+
priv->cancellable = g_cancellable_new ();
context = g_slice_new0 (Context);
diff --git a/src/e-util/e-misc-utils.c b/src/e-util/e-misc-utils.c
index 3238e2c690..d1d3c530df 100644
--- a/src/e-util/e-misc-utils.c
+++ b/src/e-util/e-misc-utils.c
@@ -4270,3 +4270,32 @@ e_util_query_ldap_root_dse_sync (const gchar *host,
return FALSE;
#endif
}
+
+/**
+ * e_util_can_preview_filename:
+ * @filename: (nullable): a file name to test
+ *
+ * Returns: Whether the @filename can be used to create a preview
+ * in GtkFileChooser and such widgets. For example directories,
+ * pipes and sockets cannot by used.
+ *
+ * Since: 3.30.5
+ **/
+gboolean
+e_util_can_preview_filename (const gchar *filename)
+{
+ GStatBuf st;
+
+ if (!filename || !*filename)
+ return FALSE;
+
+ return g_stat (filename, &st) == 0
+ && !S_ISDIR (st.st_mode)
+ #ifdef S_ISFIFO
+ && !S_ISFIFO (st.st_mode)
+ #endif
+ #ifdef S_ISSOCK
+ && !S_ISSOCK (st.st_mode)
+ #endif
+ ;
+}
diff --git a/src/e-util/e-misc-utils.h b/src/e-util/e-misc-utils.h
index abb7d209d9..30dbb17fb5 100644
--- a/src/e-util/e-misc-utils.h
+++ b/src/e-util/e-misc-utils.h
@@ -348,6 +348,7 @@ gboolean e_util_query_ldap_root_dse_sync (const gchar *host,
gchar ***out_root_dse,
GCancellable *cancellable,
GError **error);
+gboolean e_util_can_preview_filename (const gchar *filename);
G_END_DECLS
diff --git a/src/plugins/face/face.c b/src/plugins/face/face.c
index 7953bfd4b6..7c05cfa98f 100644
--- a/src/plugins/face/face.c
+++ b/src/plugins/face/face.c
@@ -163,7 +163,8 @@ prepare_image (const gchar *image_filename,
g_return_val_if_fail (file_contents != NULL, FALSE);
g_return_val_if_fail (length != NULL, FALSE);
- if (g_file_get_contents (image_filename, file_contents, length, NULL)) {
+ if (e_util_can_preview_filename (image_filename) &&
+ g_file_get_contents (image_filename, file_contents, length, NULL)) {
GError *error = NULL;
GdkPixbuf *pixbuf;
GdkPixbufLoader *loader = gdk_pixbuf_loader_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]