After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 672889 - GLib.utf8_validate does segfault
GLib.utf8_validate does segfault
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
2.32.x
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2012-03-27 06:33 UTC by Simon Schampijer
Modified: 2015-02-07 16:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
trace for segfault for utf8_validate (9.16 KB, application/octet-stream)
2012-03-27 06:33 UTC, Simon Schampijer
  Details
Fix g_utf8_validate() out argument transfer mode (1.12 KB, patch)
2012-03-27 10:27 UTC, Martin Pitt
committed Details | Review

Description Simon Schampijer 2012-03-27 06:33:32 UTC
Created attachment 210669 [details]
trace for segfault for utf8_validate

Trying to utf8 validate a string with the dynamic bindings does cause a segfault (attached is the trace):
{{{
from gi.repository import GLib
st = 'hallo'
GLib.utf8_validate(st, len(st))
}}}
Same is true when passing '-1' as max_len [1]. 

The C code does handle it fine.

Gjs does fail as well with a segfault:
{{{
const GLib = imports.gi.GLib;
GLib.utf8_validate('hallo', -1);
}}}

There has been one annotation fix in glib more recently [2].

[1] http://developer.gnome.org/glib/2.30/glib-Unicode-Manipulation.html#g-utf8-validate
[2] http://git.gnome.org/browse/glib/commit/?id=82a0733751b2dc3306e7dcf76358621eaea02bcb
Comment 1 Martin Pitt 2012-03-27 09:01:14 UTC
I confirm this. It seems to happen in the result unmarshalling:

  • #2 __libc_message
    at ../sysdeps/unix/sysv/linux/libc_fatal.c line 201
  • #3 malloc_printerr
  • #4 _pygi_marshal_cleanup_to_py_utf8
    at pygi-marshal-cleanup.c line 205
  • #5 pygi_marshal_cleanup_args_to_py_marshal_success
    at pygi-marshal-cleanup.c line 120
  • #6 _wrap_g_callable_info_invoke

It detected a "glibc", which explains why it crashed. (I still chuckle every time I see this..).

I'll have a look at this.
Comment 2 Martin Pitt 2012-03-27 10:22:21 UTC
It crashes in

    if (arg_cache->transfer == GI_TRANSFER_EVERYTHING)
        g_free (data);

in _pygi_marshal_cleanup_to_py_utf8(), when trying to free the "end" out argument.

I think what's missing here is a (transfer none) annotation, as the "end" argument is a bit special here: it's not a "classic" out argument which gets allocated by the called function, but merely points into one of its input arguments. As per https://live.gnome.org/GObjectIntrospection/Annotations#Default_Annotations (out) arguments are "transfer full" by default, so we need to annotate it explicitly.
Comment 3 Martin Pitt 2012-03-27 10:27:19 UTC
Created attachment 210683 [details] [review]
Fix g_utf8_validate() out argument transfer mode

With this patch, and refreshing g-i the call now works better:

$ jhbuild run python -c 'from gi.repository import GLib; st = "hallo"; print GLib.utf8_validate(st, len(st))'
(True, '')

In the "invalid UTF-8" case the result is still weird, though:

$ jhbuild run python -c 'from gi.repository import GLib; st = b"a\xFF"; print GLib.utf8_validate(st, len(st))'
(False, '^G\x02')

The returned result is obviously a random piece of memory, so that part could still be a pygobject bug. But at least this fixes the crash in Python and JavaScript.
Comment 4 Emmanuele Bassi (:ebassi) 2012-03-27 10:31:20 UTC
Review of attachment 210683 [details] [review]:

looks okay to me
Comment 5 Martin Pitt 2012-03-27 10:45:29 UTC
With 2.32 being out, I guess glib master is unfrozen again and I can push this?
Comment 6 Martin Pitt 2012-04-22 15:09:49 UTC
Comment on attachment 210683 [details] [review]
Fix g_utf8_validate() out argument transfer mode

This got committed a while ago.
Comment 7 Micah Carrick 2012-06-17 15:15:45 UTC
You sure this got commited? I'm still crashing in Python with glib and pygobject built with jhbuild.
Comment 8 Martin Pitt 2012-06-18 05:40:57 UTC
Erk, indeed. I pushed it to trunk now.
Comment 9 André Klapper 2015-02-07 16:58:07 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]