Re: [spice-gtk v2] file-xfer: Fix bad filename encoding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 13, 2017 at 12:26:04PM +0200, Victor Toso wrote:
> From: Victor Toso <me@xxxxxxxxxxxxxx>
> 
> Manual for G_FILE_ATTRIBUTE_STANDARD_NAME states:
>  > The name is the on-disk filename which may not be in any known
>  > encoding, and can thus not be generally displayed as is.
> 
> Considering a file named "ěščřžýáíé", if we use
> G_FILE_ATTRIBUTE_STANDARD_NAME get the file name, we will have the
> following 72 char long string:

I'd use "bytes" rather than "char"

> "\xc4\x9b\xc5\xa1\xc4\x8d\xc5\x99\xc5\xbe\xc3\xbd\xc3\xa1\xc3\xad\xc3\xa9"
> 
> This is a regression introduced at 4647ac9a2a72c98b6841180ccf5f8d
> 
> Possible solutions are:
> 1) Using G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute;
> 2) Using g_file_info_get_attribute_byte_string() function;
> 3) Using the g_file_get_basename() which was used before 4647ac9a2a72c9
> 
> Using option 2 based on better long term solution.
> This give us the correct 18 length long utf-8 string to "ěščřžýáíé"

same here, s/length/bytes/

(when utf8/unicode is involved, the char VS bytes distinction is quite
important as one char is potentially encoded using multiple bytes)

Acked-by: Christophe Fergeau <cfergeau@xxxxxxxxxx>

Christophe

> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1440206
> Signed-off-by: Victor Toso <victortoso@xxxxxxxxxx>
> ---
>  src/channel-main.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/channel-main.c b/src/channel-main.c
> index be7c852..bbc5905 100644
> --- a/src/channel-main.c
> +++ b/src/channel-main.c
> @@ -2831,7 +2831,8 @@ static void file_xfer_init_task_async_cb(GObject *obj, GAsyncResult *res, gpoint
>      GFileInfo *info;
>      SpiceFileTransferTask *xfer_task;
>      SpiceMainChannel *channel;
> -    gchar *string, *basename;
> +    gchar *string;
> +    const gchar *basename;
>      GKeyFile *keyfile;
>      VDAgentFileXferStartMessage msg;
>      guint64 file_size;
> @@ -2846,7 +2847,7 @@ static void file_xfer_init_task_async_cb(GObject *obj, GAsyncResult *res, gpoint
>          goto failed;
>  
>      channel = spice_file_transfer_task_get_channel(xfer_task);
> -    basename = g_file_info_get_attribute_as_string(info, G_FILE_ATTRIBUTE_STANDARD_NAME);
> +    basename = g_file_info_get_attribute_byte_string(info, G_FILE_ATTRIBUTE_STANDARD_NAME);
>      file_size = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
>  
>      xfer_op = data;
> @@ -2855,7 +2856,6 @@ static void file_xfer_init_task_async_cb(GObject *obj, GAsyncResult *res, gpoint
>      keyfile = g_key_file_new();
>      g_key_file_set_string(keyfile, "vdagent-file-xfer", "name", basename);
>      g_key_file_set_uint64(keyfile, "vdagent-file-xfer", "size", file_size);
> -    g_free(basename);
>  
>      /* Save keyfile content to memory. TODO: more file attributions
>         need to be sent to guest */
> -- 
> 2.12.2
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/spice-devel

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]