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