Richard W.M. Jones
2023-Feb-14 18:51 UTC
[Libguestfs] [PATCH 2/2] python: Use bytes instead of str for event callback buffer
The event callback gets a buffer parameter which is usually something like a log message. However as it comes from C it is not necessarily well-formed (eg) UTF-8 but could contain any old byte sequence. In the test case provided by the reported, we failed to encode the buffer as str with this error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 137: unexpected end of data Use bytes instead. Reported-by: Yonatan Shtarkman See: https://listman.redhat.com/archives/libguestfs/2023-February/030653.html --- python/handle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/handle.c b/python/handle.c index f37e939e03..bf639b5789 100644 --- a/python/handle.c +++ b/python/handle.c @@ -131,7 +131,7 @@ guestfs_int_py_event_callback_wrapper (guestfs_h *g, } /* XXX As with Perl we don't pass the guestfs_h handle here. */ - args = Py_BuildValue ("(Kis#O)", + args = Py_BuildValue ("(Kiy#O)", (unsigned PY_LONG_LONG) event, event_handle, buf, buf_len, py_array); if (args == NULL) { -- 2.39.0
Richard W.M. Jones
2023-Feb-15 13:27 UTC
[Libguestfs] [PATCH 2/2] python: Use bytes instead of str for event callback buffer
The series was pushed as: https://github.com/libguestfs/libguestfs/commit/6ef5837e2d8c5d4d83eff51c0201eb2e08f719de https://github.com/libguestfs/libguestfs/commit/bbf396fc5562b4f0e27132f6b10c8a503f71effc -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Laszlo Ersek
2023-Feb-16 14:22 UTC
[Libguestfs] [PATCH 2/2] python: Use bytes instead of str for event callback buffer
On 2/14/23 19:51, Richard W.M. Jones wrote:> The event callback gets a buffer parameter which is usually something > like a log message. However as it comes from C it is not necessarily > well-formed (eg) UTF-8 but could contain any old byte sequence. > > In the test case provided by the reported, we failed to encode the > buffer as str with this error: > > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 137: unexpected end of data > > Use bytes instead. > > Reported-by: Yonatan Shtarkman > See: https://listman.redhat.com/archives/libguestfs/2023-February/030653.html > --- > python/handle.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/python/handle.c b/python/handle.c > index f37e939e03..bf639b5789 100644 > --- a/python/handle.c > +++ b/python/handle.c > @@ -131,7 +131,7 @@ guestfs_int_py_event_callback_wrapper (guestfs_h *g, > } > > /* XXX As with Perl we don't pass the guestfs_h handle here. */ > - args = Py_BuildValue ("(Kis#O)", > + args = Py_BuildValue ("(Kiy#O)", > (unsigned PY_LONG_LONG) event, event_handle, > buf, buf_len, py_array); > if (args == NULL) {Looks reasonable, per Py_BuildValue() spec. Reviewed-by: Laszlo Ersek <lersek at redhat.com>