libgit2 / libgit2/libgit2sharp

Access Violation on pushing to a new remote

Open
#1,981 1 comment 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
  using var repository = new Repository(_options.LocalRepositoryPath);
            const string message = "message";
            var commitOptions = new CommitOptions()
            {
                AllowEmptyCommit = false,
                PrettifyMessage = true,
            };
            var authorSignature = new Signature(_options.Username, _options.Email, DateTimeOffset.UtcNow);

            await UpdateReadmeFile();

            repository.Index.Add("readme.md");
            repository.Index.Write();

            Commands.Stage(repository, "*");

            repository.Commit(message, authorSignature, authorSignature, commitOptions);

            PushOptions pushOptions = new PushOptions()
            {
                CredentialsProvider = (_, __, ___) => new DefaultCredentials(),               
            };

            _logger.LogInformation("Pushing changes to remote");
            _logger.LogDebug($"Branch has been tracked: {branch.IsTracking}");        

            repository.Network.Push(branch, pushOptions);
Expected behavior

Another error should occur when the local branch is not being tracked. But not an access violation exception.

Actual behavior

This craches with:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
   at LibGit2Sharp.Core.NativeMethods.git_branch_upstream_name(LibGit2Sharp.Core.Handles.GitBuf, LibGit2Sharp.Core.git_repository*, System.String)
--------------------------------
   at LibGit2Sharp.Core.Proxy.git_branch_upstream_name(LibGit2Sharp.Core.Handles.RepositoryHandle, System.String)
   at LibGit2Sharp.Branch.ResolveTrackedBranch()
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ViaFactory(System.Threading.LazyThreadSafetyMode)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ExecutionAndPublication(System.LazyHelper, Boolean)
   at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CreateValue()
   at LibGit2Sharp.Branch.get_IsTracking()
Version of LibGit2Sharp (release number or SHA1)
Operating system(s) tested; .NET runtime tested

OS: Windows 10 Professional
.NET runtime: NET 6.0

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

Reproduce the provided push flow on Windows 10 with .NET 6, focusing on repository.Network.Push and the branch.IsTracking access shown in the stack trace. Inspect Branch.ResolveTrackedBranch and the git_branch_upstream_name call; done means an untracked local branch produces an ordinary error rather than an access violation.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, git
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.