GNOME Bugzilla – Bug 676603
setting a property using the wrong type segfaults
Last modified: 2012-06-05 10:02:15 UTC
Using pygobject-3.2.2, libsoup-2.38.1 and python 2.7 (on debian sid or a gentoo system), the following code: from gi.repository import Soup msg = Soup.Message() msg.props.uri = 'http://www.gnome.org/' segfaults with the following backtrace (truncated when it hits cpython):
+ Trace 230256
Note the "uri" property is documented to be of type SoupUri, not string. So this probably *should* fail, but preferably with a python TypeError, not a segfault.
We need to check that it's actually a PygBoxed. We should also check to make sure that the object matches introspection info.
Created attachment 214715 [details] [review] attempt at a patch Not hindered by any knowledge of pygobject I attempted to patch this. It looks like there's two bugs: - pygi_set_property_value_real does not check if _pygi_argument_from_object fails (set an exception). Added a PyErr_Occurred check. - _pygi_argument_from_object assumes the python object is a GBoxed if its target type is. Added what I *hope* is the correct pyg_boxed_check call, but someone who actually knows what they're doing should check :) With this patch applied everything seems much happier: >>> from gi.repository import Soup >>> msg = Soup.Message() >>> msg.props.uri = 'http://www.gnome.org/' Traceback (most recent call last):
+ Trace 230257
>>> uri = Soup.URI() >>> msg.props.uri = uri (process:1624): libsoup-WARNING **: (soup-uri.c:523):soup_uri_copy: runtime check failed: (SOUP_URI_IS_VALID (uri)) >>> cookie = Soup.Cookie() >>> msg.props.uri = cookie Traceback (most recent call last):
Created attachment 214716 [details] [review] more appropriately formatted attempt at a patch, against git It has been pointed out to me that the quick-and-dirty patch I previously attached violates the rules of common decency for patch submission. Let me attempt to rectify that: The attached patch against git master adds a necessary type check to _pygi_argument_from_object, which previously just assumed its python argument was a GBoxed if that's what it was asked to produce. The other issue fixed by my previous patch (missing PyErr_Occurred check) was already fixed in master. This could probably still do with a unit test, but I'm hoping someone will beat me to writing that one.
> Not hindered by any knowledge of pygobject I attempted to patch this. *chuckle* Thanks for this! I added a boxed struct property to GIMarshallingTests: http://git.gnome.org/browse/gobject-introspection/commit/?id=5b8f63cb767424008a0549a28177574eb7538be9 and use that to add a test case for this bug. Committed that with your patch: http://git.gnome.org/browse/pygobject/commit/?id=635a7d1b48d99ddd1ea123797c493b18b0cdfd45