[Spice-devel] [spice-gtk v1] file-xfer: Fix bad filename encoding

Frediano Ziglio fziglio at redhat.com
Wed Apr 12 11:19:54 UTC 2017


> 
> From: Victor Toso <me at victortoso.com>
> 
> 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:
> "\xc4\x9b\xc5\xa1\xc4\x8d\xc5\x99\xc5\xbe\xc3\xbd\xc3\xa1\xc3\xad\xc3\xa9"
> 

this string is only 18 characters long, why 72 ?

> We should be use G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME instead which
> will give us the correct 18 long utf-8 string: "ěščřžýáíé"
> 

I think this solves the encoding as we'll transmit with a given encoding
(utf8).
If the source filename is not correctly encoded this will give a
destination filename different from the source.
As the protocol does not include an encoding utf-8 is a good choice
as ASCII compatible and in theory should be able to encode every
possible name set (beside invalid one of course).
As we deal with different OSes and encodings (ie utf8 in Linux and
utf16 in Windows) having a super set is probably the best solution.
A question could be: Is is better
  basename = g_file_info_get_attribute_as_string(info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
or
  basename = g_file_info_get_attribute_as_byte_string(info, G_FILE_ATTRIBUTE_STANDARD_NAME);
(as my previous consideration I think the first).

Maybe the name G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME is
confusing here as we just want the standard utf-8 encoded
name, not something just to display to the user.
A comment could help.

> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1440206
> 
> Signed-off-by: Victor Toso <victortoso at redhat.com>
> ---
>  src/channel-main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/channel-main.c b/src/channel-main.c
> index be7c852..c8de5f3 100644
> --- a/src/channel-main.c
> +++ b/src/channel-main.c
> @@ -2846,7 +2846,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_as_string(info,
> G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
>      file_size = g_file_info_get_attribute_uint64(info,
>      G_FILE_ATTRIBUTE_STANDARD_SIZE);
>  
>      xfer_op = data;

I would be curious to see different OSes with even extra plane 0
characters.

Frediano


More information about the Spice-devel mailing list