libgit2 / libgit2/libgit2sharp

Crash calling Repository.IsValid with corrupt .git/config

Open
#1,851 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
3.5k
Forks
925
PR merge metrics
No merged PRs in 30d

Description

Reproduction steps

Add this to .git/config
[diff "mytool"] command = c:\path\to\my\tool\MyToolComparer.exe
This will cause the following effect for git

c:\my\git\repo> git status
fatal: bad config line 8 in file .git/config

Then call Repository.IsValid(@"c:\my\git\repo\.git") which is turn calls Proxy.git_repository_open_ext(path, RepositoryOpenFlags.NoSearch, null);

This fails because the return value from NativeMethods.git_repository_open_ext(out repo, path, flags, ceilingDirs) is not checked for error prior to freeing the out parameter repo (which is already free'd when there is an error condition in int git_repository_open_ext(git_repository **repo_ptr, const char *start_path, unsigned int flags, const char *ceiling_dirs))

Expected behavior

LibGit2Sharp.LibGit2SharpException

Actual behavior

Access violation (0xC0000005) in void git_repository_free(git_repository *repo) when dereferencing the null repo

Version of LibGit2Sharp (release number or SHA1)

0.27.0.34

Operating system(s) tested; .NET runtime tested

Windows 10 Pro 1909 - .NET CLR Version v4.0.30319

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Repository.IsValid and trace its call through Proxy.git_repository_open_ext to NativeMethods.git_repository_open_ext, then inspect the native error path involving git_repository_free. Reproduce the corrupt .git/config case on Windows and verify that it raises LibGit2SharpException instead of an access violation; add or update coverage for this scenario if the existing test layout identifies a suitable location.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, git
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.