[Spice-devel] [PATCH] fix bug: display error when dragging file with CJK characters

Christophe Fergeau cfergeau at redhat.com
Mon Aug 11 03:23:23 PDT 2014


Hey,

On Fri, Aug 08, 2014 at 02:22:30AM +0800, Cody Chan wrote:
> I submitted a patch several months ago about this issue,
> here
> http://lists.freedesktop.org/archives/spice-devel/2014-February/016158.html
> 
> I check it again, and find that the value of
> g_key_file_to_data(keyfile,...) is always utf-8,
> for the value of g_uri_list_extract_uris() is utf8 urlencode.
> 
> So the display problem is caused by vd_agent, but how it displays depends
> on the
> language of system, the following two screenshots show the difference:
> http://int64ago-tmp.qiniudn.com/guest-Chinese.png
> http://int64ago-tmp.qiniudn.com/guest-English.png
> 
> ---
>  vdagent/file_xfer.cpp | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
> index e402eb2..553a3f3 100644
> --- a/vdagent/file_xfer.cpp
> +++ b/vdagent/file_xfer.cpp
> @@ -81,7 +81,10 @@ void FileXfer::handle_start(VDAgentFileXferStartMessage*
> start,
> 
>      strcat(file_path, "\\");
>      strcat(file_path, file_name);
> -    handle = CreateFileA(file_path, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0,
> NULL);
> +    int len = MultiByteToWideChar(CP_UTF8, 0, file_path, -1, NULL, 0);

We need to check if len is 0 as this indicates a MultiByteToWideChar
failure.

> +    wchar_t wfile_path[MAX_PATH];
> +    MultiByteToWideChar(CP_UTF8, 0, file_path, -1, wfile_path, len);

Shouldn't we allocate a wfile_path so that it can contain 'len'
characters? What happens if 'len' is bigger than MAX_PATH?

> +    handle = CreateFileW(wfile_path, GENERIC_WRITE, 0, NULL, CREATE_NEW,
> 0, NULL);

I think CreateFile could be used here instead of CreateFileW as we are
building with -DUNICODE/-D_UNICODE ?

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20140811/46f2c46d/attachment.sig>


More information about the Spice-devel mailing list