Blame SOURCES/0013-file-xfer-Fix-bad-filename-encoding.patch

18559f
From bfd5040f4a082441c143c128d13063d28ddc1e32 Mon Sep 17 00:00:00 2001
18559f
From: Victor Toso <me@victortoso.com>
18559f
Date: Thu, 13 Apr 2017 14:32:55 +0200
18559f
Subject: [PATCH 13/13] file-xfer: Fix bad filename encoding
18559f
MIME-Version: 1.0
18559f
Content-Type: text/plain; charset=UTF-8
18559f
Content-Transfer-Encoding: 8bit
18559f
18559f
Manual for G_FILE_ATTRIBUTE_STANDARD_NAME states:
18559f
 > The name is the on-disk filename which may not be in any known
18559f
 > encoding, and can thus not be generally displayed as is.
18559f
18559f
Considering a file named "ěščřžýáíé", if we use
18559f
G_FILE_ATTRIBUTE_STANDARD_NAME to get the file name, we will have the
18559f
following 72 bytes long string:
18559f
"\xc4\x9b\xc5\xa1\xc4\x8d\xc5\x99\xc5\xbe\xc3\xbd\xc3\xa1\xc3\xad\xc3\xa9"
18559f
18559f
This is a regression introduced at 4647ac9a2a72c98b6841180ccf5f8d
18559f
18559f
Possible solutions are:
18559f
1) Using G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute;
18559f
2) Using g_file_info_get_attribute_byte_string() function;
18559f
3) Using the g_file_get_basename() which was used before 4647ac9a2a72c9
18559f
18559f
Using option 2 based on better long term solution.
18559f
This give us the correct 18 bytes long utf-8 string to "ěščřžýáíé"
18559f
18559f
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1440206
18559f
Signed-off-by: Victor Toso <victortoso@redhat.com>
18559f
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
18559f
(cherry picked from commit 5b9ad92814e3fc488cca8cba41b6af0caa390e1b)
18559f
---
18559f
 src/channel-main.c | 6 +++---
18559f
 1 file changed, 3 insertions(+), 3 deletions(-)
18559f
18559f
diff --git a/src/channel-main.c b/src/channel-main.c
18559f
index 990a06a..b0878dd 100644
18559f
--- a/src/channel-main.c
18559f
+++ b/src/channel-main.c
18559f
@@ -2822,7 +2822,8 @@ static void file_xfer_init_task_async_cb(GObject *obj, GAsyncResult *res, gpoint
18559f
     GFileInfo *info;
18559f
     SpiceFileTransferTask *xfer_task;
18559f
     SpiceMainChannel *channel;
18559f
-    gchar *string, *basename;
18559f
+    gchar *string;
18559f
+    const gchar *basename;
18559f
     GKeyFile *keyfile;
18559f
     VDAgentFileXferStartMessage msg;
18559f
     guint64 file_size;
18559f
@@ -2837,7 +2838,7 @@ static void file_xfer_init_task_async_cb(GObject *obj, GAsyncResult *res, gpoint
18559f
         goto failed;
18559f
 
18559f
     channel = spice_file_transfer_task_get_channel(xfer_task);
18559f
-    basename = g_file_info_get_attribute_as_string(info, G_FILE_ATTRIBUTE_STANDARD_NAME);
18559f
+    basename = g_file_info_get_attribute_byte_string(info, G_FILE_ATTRIBUTE_STANDARD_NAME);
18559f
     file_size = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
18559f
 
18559f
     xfer_op = data;
18559f
@@ -2846,7 +2847,6 @@ static void file_xfer_init_task_async_cb(GObject *obj, GAsyncResult *res, gpoint
18559f
     keyfile = g_key_file_new();
18559f
     g_key_file_set_string(keyfile, "vdagent-file-xfer", "name", basename);
18559f
     g_key_file_set_uint64(keyfile, "vdagent-file-xfer", "size", file_size);
18559f
-    g_free(basename);
18559f
 
18559f
     /* Save keyfile content to memory. TODO: more file attributions
18559f
        need to be sent to guest */
18559f
-- 
18559f
2.12.2
18559f