Skip to content

[BUG] Crash on gio::ListStore::find_with_equal_func when no instance of item-type exists #1767

@pjungkamp

Description

@pjungkamp

Bug description

The find_with_equal_func function of gio::ListStore causes a segfault if no instance of item-type has been created yet.

Cause

GLib will only create a GType's class structure when a first instance of that type has been created. See https://docs.gtk.org/gobject/concepts.html#initialization-and-destruction

The gio::ListStore::find_with_equal_func function tries to work around the pre GLib 2.76 restriction that the item parameter cannot be NULL, by creating a "dummy" GObject instance. See https://gtk-rs.org/gtk-rs-core/stable/latest/docs/src/gio/list_store.rs.html#203-247

Note the call to glib::gobject_ffi::g_type_class_peek. This call should return a pointer to a GTypeClass for the item-type, but it won't if there has never been an instance of that type. This means that the g_class pointer of the "dummy" type instance will be NULL. The SEGFAULT is then caused by the dereference of this null-pointer as part of the g_type_is_a check at the beginning of the g_list_store_find_with_equal_func_full function. See https://gitlab.gnome.org/GNOME/glib/-/blob/main/gio/gliststore.c#L583-584

Solution

For gobject versions prior to 2.76: If self.n_items() == 0 return None without calling into C.

For current gobject versions: Skip the dummy item entirely and just pass a NULL item.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions