Segfault in gi_function_info_prep_invoker
Reproducer:
#include <girepository.h>
#include <girffi.h>
int main(void) {
GError *error = NULL;
gi_repository_require(NULL, "GLib", "2.0", 0, &error);
g_assert(!error);
GIFunctionInfo *func_info = (GIFunctionInfo*) gi_repository_find_by_name(NULL, "GLib", "get_locale_variants");
g_assert(func_info);
GIFunctionInvoker invoker;
gi_function_info_prep_invoker(func_info, &invoker, &error);
g_assert(!error);
return 0;
}
Compile with gcc -o bug bug.c $(pkg-config --cflags --libs girepository-2.0)
Crashes in GI_BASE_INFO_GET_CLASS()
at gibaseinfo.c:551.
Stack:
#0 gi_base_info_get_info_type (info=0x7fffffffdca0)
at ../subprojects/glib/girepository/gibaseinfo.c:551
#1 0x00007ffff7d9508b in gi_arg_info_load_type (info=0x7fffffffdca0, type=0x7fffffffdcd0)
at ../subprojects/glib/girepository/giarginfo.c:353
#2 0x00007ffff7da14f3 in gi_callable_info_get_ffi_arg_types
(callable_info=0x4128a0, n_args_p=0x7fffffffdd64)
at ../subprojects/glib/girepository/girffi.c:210
#3 0x00007ffff7da17df in gi_function_invoker_new_for_address
(addr=0x7ffff7e0aa90 <g_get_locale_variants>, info=0x4128a0, invoker=0x7fffffffddd0, error=0x7fffffffde10) at ../subprojects/glib/girepository/girffi.c:331
#4 0x00007ffff7da173d in gi_function_info_prep_invoker
(info=0x4128a0, invoker=0x7fffffffddd0, error=0x7fffffffde10)
at ../subprojects/glib/girepository/girffi.c:296
#5 0x0000000000401203 in main ()
In frame 2, p arg_info
:
$1 = {parent = {parent_instance = {
g_class = <error reading variable: Cannot access memory at address 0x0>},
ref_count = 2147483647, repository = 0x40faf0, container = 0x4128a0, typelib = 0x40c250,
offset = 142528, type_is_embedded = 0}}
arg_info
is stack-allocated and has just been filled in by gi_callable_info_load_arg()
. I suspect that it doesn't properly fill in the parent instance and so the GObject class machinery doesn't work.
See also #3217 (closed). If we remove the stack-allocated introspection info from the public API, we probably cannot use them internally either.