GNOME Bugzilla – Bug 707887
Attempting to create GObject Property with underscore prefix segfaults
Last modified: 2013-10-02 02:46:32 UTC
Example: from gi.repository import GObject class O(GObject.Object): _value = GObject.Property(type=int) ./gi/_gobject/__init__.py:58: Warning: g_param_spec_internal: assertion '(name[0] >= 'A' && name[0] <= 'Z') || (name[0] >= 'a' && name[0] <= 'z')' failed _gobject.type_register(cls, namespace.get('__gtype_name__')) Segmentation fault (core dumped) This is most likely due to the prefixed underscore being translated into a hyphen which is not a valid property name. We should make sure this doesn't crash and perhaps give a nicer error back to Python.
Moving to GLib. After debugging it looks like g_param_spec_int is not checking the results of g_param_spec_internal (which returns NULL for badly named properties). https://git.gnome.org/browse/glib/tree/gobject/gparamspecs.c?id=2.37.7#n1731 I'm happy to submit a patch if others think a NULL check and return after the g_param_spec_internal seems right.
A patch is welcome. Please take care to look at the full range of types in gparamspecs.c -- just about every one of them is affected by the same issue. I think the correct thing to do if you see NULL returned is just to return NULL immediately... the critical will already have been logged by _internal(). Thanks!
Created attachment 256175 [details] [review] Fix crashes in various GParamSpec creation functions Add NULL check and return after calls to g_param_spec_internal in GParamSpec creation functions. This avoids glib crashing due to things like badly named properties. Notes: I verified this fixes things on the PyGObject side (PyGObject was already checking for NULL and raising an exception which we get in addition to the glib warning). https://git.gnome.org/browse/pygobject/tree/gi/_gobject/gobjectmodule.c?id=3.10.0#n648
Review of attachment 256175 [details] [review]: This looks safe. But note that bindings should still ensure preconditions are met before invoking these functions.
Attachment 256175 [details] pushed as 2f57139 - Fix crashes in various GParamSpec creation functions