Subject: bug#47797: Segmentation fault when calling 'git-predicate' in a package file

From: Ingo Ruhnke <[email-masked]>
Date: Thu, 15 Apr 2021 15:21:39 +0200

Calling git-predicate from a simple package file causes guix to segfault.
Bisect traced it down to this commit:

commit c1940fde43c7aca37d67589cc5cb248086d17d56
Author: Ludovic Courtès <[email-masked]>
Date:   Fri Mar 19 11:51:20 2021 +0100

    git-download: Autoload Guile-Git.

    * guix/git-download.scm: Autoload (git ...) modules.

Steps to reproduce the issue:

$ cat mypkg.scm
(use-modules (guix git-download))
(git-predicate "/tmp")

$ guix package -f mypkg.scm
Segmentation fault (core dumped)

$ guix --version
guix (GNU Guix) 1bab9b9f17256a9e4f45f5b0cceb8b52e0a1b1ed

(gdb) where
#0  0x0000000000000000 in ?? ()
#1  0x00007fffeb0f44c4 in git_buf_try_grow () from
/gnu/store/jil14glx1j7mrj4cvzmw876rzyv7i960-libgit2-1.1.0/lib/libgit2.so
#2  0x00007fffeb0f47a5 in git_buf_set () from
/gnu/store/jil14glx1j7mrj4cvzmw876rzyv7i960-libgit2-1.1.0/lib/libgit2.so
#3  0x00007fffeb146fe7 in git_path_prettify () from
/gnu/store/jil14glx1j7mrj4cvzmw876rzyv7i960-libgit2-1.1.0/lib/libgit2.so
#4  0x00007fffeb15b3ad in find_repo () from
/gnu/store/jil14glx1j7mrj4cvzmw876rzyv7i960-libgit2-1.1.0/lib/libgit2.so
#5  0x00007fffeb15c28b in git_repository_discover () from
/gnu/store/jil14glx1j7mrj4cvzmw876rzyv7i960-libgit2-1.1.0/lib/libgit2.so
#6  0x00007ffff7c1266d in ffi_call_unix64 () from
/gnu/store/bw15z9kh9c65ycc2vbhl2izwfwfva7p1-libffi-3.3/lib/libffi.so.7
#7  0x00007ffff7c10ac0 in ffi_call_int () from
/gnu/store/bw15z9kh9c65ycc2vbhl2izwfwfva7p1-libffi-3.3/lib/libffi.so.7
#8  0x00007ffff7edefbe in scm_i_foreign_call () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#9  0x00007ffff7f4d904 in foreign_call () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#10 0x00007ffff7f54118 in vm_regular_engine () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#11 0x00007ffff7f555b5 in scm_call_n () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#12 0x00007ffff7ed2d27 in scm_primitive_eval () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#13 0x00007ffff7ed2d83 in scm_eval () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#14 0x00007ffff7f2b830 in scm_shell () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#15 0x00007ffff7eea73d in invoke_main_func () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#16 0x00007ffff7eccb0a in c_body () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#17 0x00007ffff7f54149 in vm_regular_engine () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#18 0x00007ffff7f555b5 in scm_call_n () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#19 0x00007ffff7ed1bba in scm_call_2 () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#20 0x00007ffff7ed33ba in scm_c_with_exception_handler () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#21 0x00007ffff7f4ac3d in scm_c_catch () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#22 0x00007ffff7ecd0b3 in scm_i_with_continuation_barrier () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#23 0x00007ffff7ecd145 in scm_c_with_continuation_barrier () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#24 0x00007ffff7f496df in with_guile () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#25 0x00007ffff7c56a68 in GC_call_with_stack_base () from
/gnu/store/iycnpxxrg8m9wf9w58d6zvp9sdby6m9d-libgc-7.6.12/lib/libgc.so.1
#26 0x00007ffff7f499f8 in scm_with_guile () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#27 0x00007ffff7eea8b2 in scm_boot_guile () from
/gnu/store/q8brh7j5mwy0hbrly6hjb1m3wwndxqc8-guile-3.0.5/lib/libguile-3.0.so.1
#28 0x000000000040119a in main ()