<div dir="ltr">If it possible to fix a typo in the commit message while submitting it will be great:<div><br></div><div>SLES4 -> SLES11 SP4<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 20, 2020 at 3:59 PM Daniel P. Berrangé <<a href="mailto:berrange@redhat.com">berrange@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mon, Apr 20, 2020 at 03:37:16PM +0300, Sam Eiderman wrote:<br>
> The python3 bindings create unicode objects from application strings<br>
> on the guest (i.e. installed rpm, deb packages).<br>
> It is documented that rpm package fields such as description should be<br>
> utf8 encoded - however in some cases they are not a valid unicode<br>
> string, on SLES11 SP4 the following packages fail to be converted to<br>
> unicode using guestfs_int_py_fromstring() (which invokes<br>
> PyUnicode_FromString()):<br>
> <br>
>  PackageKit<br>
>  aaa_base<br>
>  coreutils<br>
>  dejavu<br>
>  desktop-data-SLED<br>
>  gnome-utils<br>
>  hunspell<br>
>  hunspell-32bit<br>
>  hunspell-tools<br>
>  libblocxx6<br>
>  libexif<br>
>  libgphoto2<br>
>  libgtksourceview-2_0-0<br>
>  libmpfr1<br>
>  libopensc2<br>
>  libopensc2-32bit<br>
>  liborc-0_4-0<br>
>  libpackagekit-glib10<br>
>  libpixman-1-0<br>
>  libpixman-1-0-32bit<br>
>  libpoppler-glib4<br>
>  libpoppler5<br>
>  libsensors3<br>
>  libtelepathy-glib0<br>
>  m4<br>
>  opensc<br>
>  opensc-32bit<br>
>  permissions<br>
>  pinentry<br>
>  poppler-tools<br>
>  python-gtksourceview<br>
>  splashy<br>
>  syslog-ng<br>
>  tar<br>
>  tightvnc<br>
>  xorg-x11<br>
>  xorg-x11-xauth<br>
>  yast2-mouse<br>
> <br>
> Fix this by globally changing guestfs_int_py_fromstring()<br>
> and guestfs_int_py_fromstringsize() to decode utf-8 with the "replace"<br>
> error handler:<br>
> <br>
>  <a href="https://docs.python.org/3/library/codecs.html#error-handlers" rel="noreferrer" target="_blank">https://docs.python.org/3/library/codecs.html#error-handlers</a><br>
> <br>
> For example, this will decode PackageKit's description on SLES4 the<br>
> following way:<br>
> <br>
>     Backend: pisi<br>
>         S.�a&#287;lar Onur <<a href="mailto:caglar@pardus.org.tr" target="_blank">caglar@pardus.org.tr</a>><br>
> <br>
> Signed-off-by: Sam Eiderman <<a href="mailto:sameid@google.com" target="_blank">sameid@google.com</a>><br>
> ---<br>
>  python/handle.c | 4 ++--<br>
>  1 file changed, 2 insertions(+), 2 deletions(-)<br>
> <br>
> diff --git a/python/handle.c b/python/handle.c<br>
> index 2fb8c18f0..427424707 100644<br>
> --- a/python/handle.c<br>
> +++ b/python/handle.c<br>
> @@ -387,7 +387,7 @@ guestfs_int_py_fromstring (const char *str)<br>
>  #if PY_MAJOR_VERSION < 3<br>
>    return PyString_FromString (str);<br>
>  #else<br>
> -  return PyUnicode_FromString (str);<br>
> +  return PyUnicode_Decode(str, strlen(str), "utf-8", "replace");<br>
>  #endif<br>
>  }<br>
>  <br>
> @@ -397,7 +397,7 @@ guestfs_int_py_fromstringsize (const char *str, size_t size)<br>
>  #if PY_MAJOR_VERSION < 3<br>
>    return PyString_FromStringAndSize (str, size);<br>
>  #else<br>
> -  return PyUnicode_FromStringAndSize (str, size);<br>
> +  return PyUnicode_Decode(str, size, "utf-8", "replace");<br>
>  #endif<br>
>  }<br>
<br>
Reviewed-by: Daniel P. Berrangé <<a href="mailto:berrange@redhat.com" target="_blank">berrange@redhat.com</a>><br>
<br>
Regards,<br>
Daniel<br>
-- <br>
|: <a href="https://berrange.com" rel="noreferrer" target="_blank">https://berrange.com</a>      -o-    <a href="https://www.flickr.com/photos/dberrange" rel="noreferrer" target="_blank">https://www.flickr.com/photos/dberrange</a> :|<br>
|: <a href="https://libvirt.org" rel="noreferrer" target="_blank">https://libvirt.org</a>         -o-            <a href="https://fstop138.berrange.com" rel="noreferrer" target="_blank">https://fstop138.berrange.com</a> :|<br>
|: <a href="https://entangle-photo.org" rel="noreferrer" target="_blank">https://entangle-photo.org</a>    -o-    <a href="https://www.instagram.com/dberrange" rel="noreferrer" target="_blank">https://www.instagram.com/dberrange</a> :|<br>
<br>
</blockquote></div>