Bastien Nocera f4801b5
From b5a674a757d4ad934eb505f4e3c50ee1180f3693 Mon Sep 17 00:00:00 2001
Bastien Nocera f4801b5
From: Bastien Nocera <hadess@hadess.net>
Bastien Nocera f4801b5
Date: Tue, 8 Aug 2017 19:12:51 +0200
Bastien Nocera f4801b5
Subject: [PATCH 1/3] thumbnail: Don't crash if the thumbnailer could not be
Bastien Nocera f4801b5
 setup
Bastien Nocera f4801b5
Bastien Nocera f4801b5
script_exec_new() can fail in certain cases, and we should not crash
Bastien Nocera f4801b5
when trying to expand the script command later if the initial setup
Bastien Nocera f4801b5
failed.
Bastien Nocera f4801b5
Bastien Nocera f4801b5
https://bugzilla.gnome.org/show_bug.cgi?id=785963
Bastien Nocera f4801b5
---
Bastien Nocera f4801b5
 libgnome-desktop/gnome-desktop-thumbnail-script.c | 5 +++++
Bastien Nocera f4801b5
 1 file changed, 5 insertions(+)
Bastien Nocera f4801b5
Bastien Nocera f4801b5
diff --git a/libgnome-desktop/gnome-desktop-thumbnail-script.c b/libgnome-desktop/gnome-desktop-thumbnail-script.c
Bastien Nocera f4801b5
index 5a5f05f4..d9437d40 100644
Bastien Nocera f4801b5
--- a/libgnome-desktop/gnome-desktop-thumbnail-script.c
Bastien Nocera f4801b5
+++ b/libgnome-desktop/gnome-desktop-thumbnail-script.c
Bastien Nocera f4801b5
@@ -657,6 +657,9 @@ child_setup (gpointer user_data)
Bastien Nocera f4801b5
 static void
Bastien Nocera f4801b5
 script_exec_free (ScriptExec *exec)
Bastien Nocera f4801b5
 {
Bastien Nocera f4801b5
+  if (exec == NULL)
Bastien Nocera f4801b5
+    return;
Bastien Nocera f4801b5
+
Bastien Nocera f4801b5
   g_free (exec->infile);
Bastien Nocera f4801b5
   if (exec->outfile)
Bastien Nocera f4801b5
     {
Bastien Nocera f4801b5
@@ -757,6 +760,8 @@ gnome_desktop_thumbnail_script_exec (const char  *cmd,
Bastien Nocera f4801b5
   ScriptExec *exec;
Bastien Nocera f4801b5
 
Bastien Nocera f4801b5
   exec = script_exec_new (uri);
Bastien Nocera f4801b5
+  if (!exec)
Bastien Nocera f4801b5
+    goto out;
Bastien Nocera f4801b5
   expanded_script = expand_thumbnailing_cmd (cmd, exec, size, error);
Bastien Nocera f4801b5
   if (expanded_script == NULL)
Bastien Nocera f4801b5
     goto out;
Bastien Nocera f4801b5
-- 
Bastien Nocera f4801b5
2.13.4
Bastien Nocera f4801b5
Bastien Nocera f4801b5
Bastien Nocera f4801b5
From 99df9a83a36882d8a666176d9452283ae065d014 Mon Sep 17 00:00:00 2001
Bastien Nocera f4801b5
From: Bastien Nocera <hadess@hadess.net>
Bastien Nocera f4801b5
Date: Tue, 8 Aug 2017 19:14:09 +0200
Bastien Nocera f4801b5
Subject: [PATCH 2/3] thumbnail: Report errors when script_exec_new() fails
Bastien Nocera f4801b5
Bastien Nocera f4801b5
Makes it easier to debug.
Bastien Nocera f4801b5
Bastien Nocera f4801b5
https://bugzilla.gnome.org/show_bug.cgi?id=785963
Bastien Nocera f4801b5
---
Bastien Nocera f4801b5
 libgnome-desktop/gnome-desktop-thumbnail-script.c | 19 ++++++++++++++-----
Bastien Nocera f4801b5
 1 file changed, 14 insertions(+), 5 deletions(-)
Bastien Nocera f4801b5
Bastien Nocera f4801b5
diff --git a/libgnome-desktop/gnome-desktop-thumbnail-script.c b/libgnome-desktop/gnome-desktop-thumbnail-script.c
Bastien Nocera f4801b5
index d9437d40..1012efa8 100644
Bastien Nocera f4801b5
--- a/libgnome-desktop/gnome-desktop-thumbnail-script.c
Bastien Nocera f4801b5
+++ b/libgnome-desktop/gnome-desktop-thumbnail-script.c
Bastien Nocera f4801b5
@@ -687,7 +687,8 @@ clear_fd (gpointer data)
Bastien Nocera f4801b5
 }
Bastien Nocera f4801b5
 
Bastien Nocera f4801b5
 static ScriptExec *
Bastien Nocera f4801b5
-script_exec_new (const char *uri)
Bastien Nocera f4801b5
+script_exec_new (const char  *uri,
Bastien Nocera f4801b5
+		 GError     **error)
Bastien Nocera f4801b5
 {
Bastien Nocera f4801b5
   ScriptExec *exec;
Bastien Nocera f4801b5
   g_autoptr(GFile) file = NULL;
Bastien Nocera f4801b5
@@ -705,7 +706,11 @@ script_exec_new (const char *uri)
Bastien Nocera f4801b5
 
Bastien Nocera f4801b5
   exec->infile = g_file_get_path (file);
Bastien Nocera f4801b5
   if (!exec->infile)
Bastien Nocera f4801b5
-    goto bail;
Bastien Nocera f4801b5
+    {
Bastien Nocera f4801b5
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
Bastien Nocera f4801b5
+                   "Could not get path for URI '%s'", uri);
Bastien Nocera f4801b5
+      goto bail;
Bastien Nocera f4801b5
+    }
Bastien Nocera f4801b5
 
Bastien Nocera f4801b5
 #ifdef HAVE_BWRAP
Bastien Nocera f4801b5
   if (exec->sandbox)
Bastien Nocera f4801b5
@@ -719,7 +724,11 @@ script_exec_new (const char *uri)
Bastien Nocera f4801b5
       tmpl = g_strdup ("/tmp/gnome-desktop-thumbnailer-XXXXXX");
Bastien Nocera f4801b5
       exec->outdir = g_mkdtemp (tmpl);
Bastien Nocera f4801b5
       if (!exec->outdir)
Bastien Nocera f4801b5
-        goto bail;
Bastien Nocera f4801b5
+        {
Bastien Nocera f4801b5
+          g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
Bastien Nocera f4801b5
+                               "Could not create temporary sandbox directory");
Bastien Nocera f4801b5
+          goto bail;
Bastien Nocera f4801b5
+        }
Bastien Nocera f4801b5
       exec->outfile = g_build_filename (exec->outdir, "gnome-desktop-thumbnailer.png", NULL);
Bastien Nocera f4801b5
 
Bastien Nocera f4801b5
       ext = get_extension (exec->infile);
Bastien Nocera f4801b5
@@ -732,7 +741,7 @@ script_exec_new (const char *uri)
Bastien Nocera f4801b5
       int fd;
Bastien Nocera f4801b5
       g_autofree char *tmpname = NULL;
Bastien Nocera f4801b5
 
Bastien Nocera f4801b5
-      fd = g_file_open_tmp (".gnome_desktop_thumbnail.XXXXXX", &tmpname, NULL);
Bastien Nocera f4801b5
+      fd = g_file_open_tmp (".gnome_desktop_thumbnail.XXXXXX", &tmpname, error);
Bastien Nocera f4801b5
       if (fd == -1)
Bastien Nocera f4801b5
         goto bail;
Bastien Nocera f4801b5
       close (fd);
Bastien Nocera f4801b5
@@ -759,7 +768,7 @@ gnome_desktop_thumbnail_script_exec (const char  *cmd,
Bastien Nocera f4801b5
   GBytes *image = NULL;
Bastien Nocera f4801b5
   ScriptExec *exec;
Bastien Nocera f4801b5
 
Bastien Nocera f4801b5
-  exec = script_exec_new (uri);
Bastien Nocera f4801b5
+  exec = script_exec_new (uri, error);
Bastien Nocera f4801b5
   if (!exec)
Bastien Nocera f4801b5
     goto out;
Bastien Nocera f4801b5
   expanded_script = expand_thumbnailing_cmd (cmd, exec, size, error);
Bastien Nocera f4801b5
-- 
Bastien Nocera f4801b5
2.13.4
Bastien Nocera f4801b5
Bastien Nocera f4801b5
Bastien Nocera f4801b5
From f96041679f46ece036d742bde7d78afc67d73519 Mon Sep 17 00:00:00 2001
Bastien Nocera f4801b5
From: Bastien Nocera <hadess@hadess.net>
Bastien Nocera f4801b5
Date: Tue, 8 Aug 2017 19:20:31 +0200
Bastien Nocera f4801b5
Subject: [PATCH 3/3] thumbnail: And print those errors in the debug
Bastien Nocera f4801b5
Bastien Nocera f4801b5
https://bugzilla.gnome.org/show_bug.cgi?id=785963
Bastien Nocera f4801b5
---
Bastien Nocera f4801b5
 libgnome-desktop/gnome-desktop-thumbnail.c | 9 ++++++++-
Bastien Nocera f4801b5
 1 file changed, 8 insertions(+), 1 deletion(-)
Bastien Nocera f4801b5
Bastien Nocera f4801b5
diff --git a/libgnome-desktop/gnome-desktop-thumbnail.c b/libgnome-desktop/gnome-desktop-thumbnail.c
Bastien Nocera f4801b5
index 73751f69..866fc7d2 100644
Bastien Nocera f4801b5
--- a/libgnome-desktop/gnome-desktop-thumbnail.c
Bastien Nocera f4801b5
+++ b/libgnome-desktop/gnome-desktop-thumbnail.c
Bastien Nocera f4801b5
@@ -1066,13 +1066,20 @@ gnome_desktop_thumbnail_factory_generate_thumbnail (GnomeDesktopThumbnailFactory
Bastien Nocera f4801b5
   if (script)
Bastien Nocera f4801b5
     {
Bastien Nocera f4801b5
       GBytes *data;
Bastien Nocera f4801b5
+      GError *error = NULL;
Bastien Nocera f4801b5
 
Bastien Nocera f4801b5
-      data = gnome_desktop_thumbnail_script_exec (script, size, uri, NULL);
Bastien Nocera f4801b5
+      data = gnome_desktop_thumbnail_script_exec (script, size, uri, &error);
Bastien Nocera f4801b5
       if (data)
Bastien Nocera f4801b5
         {
Bastien Nocera f4801b5
           pixbuf = pixbuf_new_from_bytes (data, NULL);
Bastien Nocera f4801b5
           g_bytes_unref (data);
Bastien Nocera f4801b5
         }
Bastien Nocera f4801b5
+      else
Bastien Nocera f4801b5
+        {
Bastien Nocera f4801b5
+          g_debug ("Thumbnail script ('%s') failed for '%s': %s",
Bastien Nocera f4801b5
+                   script, uri, error ? error->message : "no details");
Bastien Nocera f4801b5
+          g_clear_error (&error);
Bastien Nocera f4801b5
+        }
Bastien Nocera f4801b5
     }
Bastien Nocera f4801b5
 
Bastien Nocera f4801b5
   g_free (script);
Bastien Nocera f4801b5
-- 
Bastien Nocera f4801b5
2.13.4
Bastien Nocera f4801b5