Gio.InputStream.read_async() and read_all_async() cause segfaults
- OS version: Ubuntu 19.10 x86_64
- GLib version: 2.26.1
- PyGObject version: 3.34.0
Calling Gio.InputStream.read_async()
and Gio.InputStream.read_all_async()
don't correctly reference the bytes object. Both of those methods return an empty bytes object and fail to read the file. The complete buffer should probably be returned from the corresponding _finish()
methods instead. Trying to open a large file causes random memory corruption and crashing because of this. Test cases are in these two snippets:
Run them like so on some different files to test:
# try with a small file, no data is returned
python3 ./read_async.py /etc/fstab
python3 ./read_all_async.py /etc/fstab
# try with a large file, get a crash
python3 ./read_async.py /usr/bin/gnome-control-center
python3 ./read_all_async.py /usr/bin/gnome-control-center
Run it several times on a file that is larger than a few megabytes and you'll start to see random inconsistent results and crashes. Here is one of the random stack traces I get when running the second example:
Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
#0 0x00007ffff729d911 in g_datalist_id_dup_data (datalist=0xad0560, key_id=63, dup_func=0x0, user_data=0x0) at ../../../glib/gdataset.c:865
#1 0x00007ffff7410d66 in () at /usr/lib/python3/dist-packages/gi/_gi.cpython-37m-x86_64-linux-gnu.so
#2 0x0000000000580ba1 in ()
#3 0x000000000058603b in ()
#4 0x00007ffff73fbe2b in () at /usr/lib/python3/dist-packages/gi/_gi.cpython-37m-x86_64-linux-gnu.so
#5 0x00007ffff71d260b in ffi_closure_unix64_inner (closure=0x7ffff7ffb010, rvalue=0x7fffffffd4b0, reg_args=0x7fffffffd400, argp=0x7fffffffd4d0 "\200Ҭ") at ../src/x86/ffi64.c:670
#6 0x00007ffff71d2986 in ffi_closure_unix64 () at ../src/x86/unix64.S:229
#7 0x00007ffff7029029 in g_task_return_now (task=0xad0550 [GTask]) at ../../../gio/gtask.c:1212
#8 0x00007ffff702906d in complete_in_idle_cb (task=0xad0550) at ../../../gio/gtask.c:1226
#9 0x00007ffff72bc71e in g_main_dispatch (context=0xac2bd0) at ../../../glib/gmain.c:3179
#10 0x00007ffff72bc71e in g_main_context_dispatch (context=context@entry=0xac2bd0) at ../../../glib/gmain.c:3844
#11 0x00007ffff72bcad0 in g_main_context_iterate (context=context@entry=0xac2bd0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../../../glib/gmain.c:3917
#12 0x00007ffff72bcb73 in g_main_context_iteration (context=0xac2bd0, may_block=1) at ../../../glib/gmain.c:3978
#13 0x00007ffff71d281e in ffi_call_unix64 () at ../src/x86/unix64.S:76
#14 0x00007ffff71d21ef in ffi_call (cif=<optimized out>, fn=<optimized out>, rvalue=<optimized out>, avalue=<optimized out>) at ../src/x86/ffi64.c:525
#15 0x00007ffff740407d in () at /usr/lib/python3/dist-packages/gi/_gi.cpython-37m-x86_64-linux-gnu.so
#16 0x00007ffff73fb13c in () at /usr/lib/python3/dist-packages/gi/_gi.cpython-37m-x86_64-linux-gnu.so
#17 0x00007ffff73ff0fd in () at /usr/lib/python3/dist-packages/gi/_gi.cpython-37m-x86_64-linux-gnu.so
#18 0x00000000005c9e53 in _PyObject_FastCallKeywords ()
#19 0x00000000005367d1 in ()
#20 0x000000000053d361 in _PyEval_EvalFrameDefault ()
#21 0x00000000005373a7 in _PyEval_EvalCodeWithName ()
#22 0x00000000005c9358 in _PyFunction_FastCallKeywords ()
#23 0x0000000000536640 in ()
#24 0x00000000005394d3 in _PyEval_EvalFrameDefault ()
#25 0x00000000005373a7 in _PyEval_EvalCodeWithName ()
#26 0x000000000064d163 in PyEval_EvalCode ()
#27 0x00000000006407d3 in ()
#28 0x0000000000640887 in PyRun_FileExFlags ()
#29 0x000000000064163a in PyRun_SimpleFileExFlags ()
#30 0x000000000067918f in ()
#31 0x000000000067947e in _Py_UnixMain ()
#32 0x00007ffff7db81e3 in __libc_start_main (main=0x4cf960 <main>, argc=3, argv=0x7fffffffe118, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe108) at ../csu/libc-start.c:308
#33 0x00000000005cff9e in _start ()