Skip to content

Segfault in Index::add_all() with empty pathspecs slice and Some(cb) #585

@cpick

Description

@cpick

If Index::add_all() is called with an empty (&[]) pathspecs slice and Some(...) callback then it will crash.

If pathspecs is set to anything (eg &[*]) or cb is set to None then it runs without a crash.
I suspect the issue is that it's crashing trying to create the matched_pathspec argument for the callback and that the type of that argument should be changed to be an Option<&[u8]>.

Full steps to reproduce:

$ cargo new git2-crash
$ cd git2-crash
$ echo 'git2 = "0.13.6"' >> Cargo.toml
$ cat >|src/main.rs <<EOF
fn main() {
    let pathspecs: &[&str] = &[];
    git2::Repository::open(".")
        .unwrap()
        .index()
        .unwrap()
        .add_all(pathspecs, Default::default(), Some(&mut |_path, _matched_pathspec| 0))
        .unwrap();
}
EOF
$ cargo run
    Updating crates.io index
...
   Compiling git2-crash v0.1.0 (/Users/cpick/src/delme/git2-crash)
    Finished dev [unoptimized + debuginfo] target(s) in 14.64s
     Running `target/debug/git2-crash`
Segmentation fault: 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions