cargo-edit: cargo add: Segfault with libgit2 1.4.1

Hi, I just installed cargo-edit on Archlinux with cargo install cargo-edit.

Whenever I try to use cargo add in this way

cargo add scraper # example library

That’s what I get:

Updating 'https://github.com/rust-lang/crates.io-index' index
Segmentation fault (core dumped

This is the relevant section of the core dump:

Core was generated by `/home/paolo/.cargo/bin/cargo-add add scraper'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f82d2038fc0 in ?? () from /usr/lib/libgit2.so.1.4
(gdb) bt
#0  0x00007f82d2038fc0 in ?? () from /usr/lib/libgit2.so.1.4
#1  0x00007f82d203aaae in git_remote_fetch () from /usr/lib/libgit2.so.1.4
#2  0x0000555c2c59788c in git2::remote::Remote::fetch ()
#3  0x0000555c2c58c9db in crates_index::bare_index::BareIndexRepo::retrieve ()

It looks like the segfault comes from libgit2.so - although other libraries linking with it are working fine (that’s why I’m reporting it here).

The libgit2 version on Archlinux is 1:1.4.1-1 (that’s today’s update, that broke cargo-edit).

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 41
  • Comments: 17 (2 by maintainers)

Most upvoted comments

I can confirm as well, I have investigated this issue and notified upstream in rust-lang/git2-rs/issues/813. In the meantime, cargo install cargo-edit --git https://github.com/killercup/cargo-edit --force will do.

As an update, upstreaming cargo-add into cargo is now in the Final Comment Period. It’ll then have to go through the regular release process before its in people’s hands.

Installing with cargo install cargo-edit --features vendored-libgit2 seems to fix this for now, if you don’t want to use the master branch. The segfault is caused by git2 using the system’s libgit2, which had an ABI change recently.

Is there any workaround for this issue?

I can confirm. Building the master branch fixes it for me too.

I actually can’t reproduce this with cargo-edit built from current HEAD (1ae4c685).

git clone https://github.com/killercup/cargo-edit
cd cargo-edit && cargo build --release && cargo install --path .

No more segfault now.