cake-contrib / Cake_Git

Cake AddIn that extends Cake with Git features using LibGit2 and LibGit2Sharp

Home Page:https://cakebuild.net/extensions/cake-git

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Access violation calling GitHasUncommitedChanges

gmkado opened this issue · comments

This was working fine last week, not sure what changed, but calling GitHasUncommitedChanges on v1.0.1 throws the following exception:

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_status_list_new(LibGit2Sharp.Core.git_status_list* ByRef, LibGit2Sharp.Core.git_repository*, LibGit2Sharp.Core.GitStatusOptions)
--------------------------------
   at LibGit2Sharp.Core.Proxy.git_status_list_new(LibGit2Sharp.Core.Handles.RepositoryHandle, LibGit2Sharp.Core.GitStatusOptions)
   at LibGit2Sharp.RepositoryStatus..ctor(LibGit2Sharp.Repository, LibGit2Sharp.StatusOptions)
   at LibGit2Sharp.RepositoryExtensions.RetrieveStatus(LibGit2Sharp.IRepository)
   at Cake.Git.GitAliases+<>c.<GitHasUncommitedChanges>b__38_0(LibGit2Sharp.Repository)
   at Cake.Git.Extensions.RepositoryExtensions.UseRepository[[System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Cake.Core.ICakeContext, Cake.Core.IO.DirectoryPath, System.Func`2<LibGit2Sharp.Repository,Boolean>)
   at Cake.Git.GitAliases.GitHasUncommitedChanges(Cake.Core.ICakeContext, Cake.Core.IO.DirectoryPath)

Cake.Git 1.0.1 was released already in March 2021, therefore this can't be related to an update of Cake.Git.

You mention it worked last week. What have you changed? Have you updated the addin or Cake? Have you pinned addin and Cake version? Did you run any OS updates? Do you get the error while running it on the same repository as last week? Do you get the same error on other repositories?

Thanks for the quick response! It looks like there were some security updates that ran yesterday
image

I did not get the error running on the same repository last week. I also get the same error for other repositories. I didn't touch the cake script at all for either repos.

Also this is how I reference the addin:

#addin nuget:?package=Cake.Git&version=1.0.1

Looks like these might be related: libgit2/libgit2sharp#1711

I'm not using this through cake, but I'm using libgit2sharp directly. I also have this issue that since last week suddenly access violations happen when calling RetrieveStatus() of libgit.

        public bool HasUncommittedChanges()
        {
            using (var git = new Repository(Directory.FullName))
            {
                return git.RetrieveStatus().IsDirty;
            }
        }

As you can see, not much happening here on my part. It just dies. If you find any solution or workaround I'd be interested to know.

FY, we're seeing the same error when running integration tests via CI of this addin:

========================================
Git-HasUncommitedChanges-Dirty
========================================
Checking if repository has uncommited changes...
C:\projects\cake-git\tools\Cake\Cake.exe : Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
At line:1 char:1
+ C:\projects\cake-git\tools\Cake\Cake.exe "build.cake" --target="AppVe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Fatal error. Sy...ory is corrupt.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

https://ci.appveyor.com/project/cakecontrib/cake-git/builds/40242817#L702

It looks like updating to the latest LibGit2Sharp 0.27.0-preview fixes the issue libgit2/libgit2sharp#1711 (comment)

@gmkado @Xcone This has been fixed with Cake.Git v1.1.0

#addin "nuget:?package=Cake.Git&version=1.1.0"