Blame SOURCES/0045-Screenshot-reject-unknown-image-type-filenames.patch

1efd99
From 83f72567d319768cdd04755b7bd7f9201cb63403 Mon Sep 17 00:00:00 2001
1efd99
From: Jonathon Jongsma <jjongsma@redhat.com>
1efd99
Date: Wed, 19 Jul 2017 15:59:46 -0500
1efd99
Subject: [PATCH] Screenshot: reject unknown image type filenames
1efd99
1efd99
If the image format cannot be determined for a screenshot filename,
1efd99
simply return an error informing the user that this is not a valid image
1efd99
format.
1efd99
1efd99
In the past, if we couldn't determine the file type, we simply saved it
1efd99
as a PNG, and appended a ".png" file extension to the filename. This has
1efd99
several problems. First, it can result in some oddly-named files (e.g. a
1efd99
screenshot named 'Screenshot.pdf.png').
1efd99
1efd99
Second, modifying the filename that is returned from the GtkFileChooser
1efd99
undermines the overwrite-confirmation functionality that is built into
1efd99
the gtk file chooser. When the user specifies a filename in the file
1efd99
chooser dialog, the chooser will automatically check whether a file of
1efd99
that name exists, and if it does, it will display a dialog asking
1efd99
whether the user wants to overwrite it. But if we then append a ".png"
1efd99
extension to the filename and save it, we may be overwriting an existing
1efd99
file without warning. By returning an error for unrecognized file types,
1efd99
we avoid this problem.
1efd99
1efd99
Resolves: rhbz#1455832
1efd99
---
1efd99
 src/virt-viewer-window.c | 14 +++-----------
1efd99
 1 file changed, 3 insertions(+), 11 deletions(-)
1efd99
1efd99
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
1efd99
index 41794a6..a796685 100644
1efd99
--- a/src/virt-viewer-window.c
1efd99
+++ b/src/virt-viewer-window.c
1efd99
@@ -947,17 +947,9 @@ virt_viewer_window_save_screenshot(VirtViewerWindow *self,
1efd99
     gboolean result;
1efd99
 
1efd99
     if (format == NULL) {
1efd99
-        g_debug("unknown file extension, falling back to png");
1efd99
-        if (!g_str_has_suffix(file, ".png")) {
1efd99
-            char *png_filename;
1efd99
-            png_filename = g_strconcat(file, ".png", NULL);
1efd99
-            result = gdk_pixbuf_save(pix, png_filename, "png", error,
1efd99
-                                     "tEXt::Generator App", PACKAGE, NULL);
1efd99
-            g_free(png_filename);
1efd99
-        } else {
1efd99
-            result = gdk_pixbuf_save(pix, file, "png", error,
1efd99
-                                     "tEXt::Generator App", PACKAGE, NULL);
1efd99
-        }
1efd99
+        g_set_error(error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
1efd99
+                    _("Unable to determine image format for file '%s'"), file);
1efd99
+        result = FALSE;
1efd99
     } else {
1efd99
         char *type = gdk_pixbuf_format_get_name(format);
1efd99
         g_debug("saving to %s", type);
1efd99
-- 
1efd99
2.13.6
1efd99