cake-contrib / Cake_Git

Cake AddIn that extends Cake with Git features using LibGit2 and LibGit2Sharp
https://cakebuild.net/extensions/cake-git
Other
39 stars 63 forks source link

Access violation calling GitHasUncommitedChanges #145

Closed gmkado closed 3 years ago

gmkado commented 3 years ago

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)
pascalberger commented 3 years ago

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?

gmkado commented 3 years ago

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.

gmkado commented 3 years ago

Also this is how I reference the addin:

#addin nuget:?package=Cake.Git&version=1.0.1
gmkado commented 3 years ago

Looks like these might be related: https://github.com/libgit2/libgit2sharp/issues/1711

Xcone commented 3 years ago

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.

augustoproiete commented 3 years ago

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

augustoproiete commented 3 years ago

It looks like updating to the latest LibGit2Sharp 0.27.0-preview fixes the issue https://github.com/libgit2/libgit2sharp/issues/1711#issuecomment-868286918

augustoproiete commented 3 years ago

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

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