Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault or other errors when reading splitIndex #4857

Closed
glasserc opened this issue Oct 22, 2018 · 9 comments
Closed

Segmentation fault or other errors when reading splitIndex #4857

glasserc opened this issue Oct 22, 2018 · 9 comments

Comments

@glasserc
Copy link

Does libgit2 support repositories with the core.splitIndex feature turned on?

Reproduction steps

These steps are based on #4234.

$ git --version
git version 2.19.1
$ git init /tmp/test-splitindex
$ cd /tmp/test-splitindex
$ git config --add core.splitIndex true
$ git update-index --index-version=4 --split-index
$ touch file.txt
$ git add file.txt
$ git commit -m "first commit"
# Verify that .git/ has sharedindex.* files.
$ ls .git/sharedindex.*
sharedindex.4dc495dafdb005ef4f40b20e171474e626bca290
sharedindex.508851a7f0dfa8691e9f69c7f055865389012491

Try to open the index with libgit2:

#include <git2.h>
#include <stdio.h>

int main()
{
  git_repository *repo;
  git_index *index;
  int err;

  err = git_repository_open(&repo, "/tmp/test-splitindex");
  if (err < 0) {
    printf("Error opening repo\n");
    return 1;
  }

  err = git_repository_index(&index, repo);
  if (err < 0) {
    printf("%s\n", giterr_last()->message);
    return 1;
  }

  return 0;
}
$ gcc main.c -lgit2
$ ./a.out

Expected behavior

No output (i.e. success)

Actual behavior

Segmentation fault

Version of libgit2 (release number or SHA1)

0.26.6

Operating system(s) tested

NixOS unstable

Additional notes

I'm actually trying to debug an issue where cargo refuses to build code in a large repo (where I have turned on splitIndex). There, I get cryptic errors like "error: invalid data in index - extension is truncated; class=Index (10)". It may be that the two issues are related, in which case you may not get a seg fault but some other error.

@tiennou
Copy link
Contributor

tiennou commented Oct 22, 2018

A cursory look at the index code seems to confirm that split indexes are indeed not supported (here's where the error comes from, and here's the index extension handling).

As to the segfault, I can't reproduce — I've checked against an empty repo with split index enabled, and I'm getting the aforementioned error message.

@glasserc
Copy link
Author

OK, that's still pretty helpful, thanks!

@grantfar
Copy link

I will take this

@grantfar
Copy link

git_allocator_global_init is not being called and git_allocator is used in git_buf_try_grow while all the stored methods are NULL.

I don't know where it should be initialized

@pks-t
Copy link
Member

pks-t commented Oct 24, 2019 via email

@ethomson
Copy link
Member

Random idea: can we set up the allocator to a function that: git_error_set(..., "libgit2 has not been initialized"); return NULL; until such time as it's actually initialized?

@pks-t
Copy link
Member

pks-t commented Oct 24, 2019

Random idea: can we set up the allocator to a function that: git_error_set(..., "libgit2 has not been initialized"); return NULL; until such time as it's actually initialized?

Nice idea. Do we also want to re-set the struct to these error functions when calling git_libgit2_shutdown()?

@tiennou: by the way, should this bug still exist in theory? I'm asking because of your #4858, which has in the meantime been merged. We sure still lack support for the split index itself, but at least we hopefully shouldn't crash.

@grantfar
Copy link

@pks-t git_libgit2_init() not being called is why the segfault is happening.

@pks-t
Copy link
Member

pks-t commented Oct 25, 2019

Heh, funny how I haven't noticed before, but that's probably it. Thanks a lot for diving into the issue! I'm closing this ticket -- if anybody sees crashes with split index, please feel free to reopen it.

@pks-t pks-t closed this as completed Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants