libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.16k stars 888 forks source link

Attempted to read or write protected memory. This is often an indication that other memory is corrupt. #115

Closed psantosl closed 12 years ago

psantosl commented 12 years ago

Hi,

Got this:

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Running the following code:

    static void Main(string[] args)
    {
        Repository rep = new Repository(@"C:\Users\pablo\linux-2.6");

        Console.WriteLine("merges {0}", rep.Commits.Count(commit => commit.ParentsCount > 1));
    }

It fails looping through the commits.

The same happens if you do a "foreach"

nulltoken commented 12 years ago

Thanks for reporting this.

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Brrr... This is far from being an expected behavior ;-) I'm going to dig into this.

nulltoken commented 12 years ago

@psantosl Hum. I can't reproduce this issue :-/

Following test outputs merges 18653

[Test]
public void CanCountMergeCommits()
{
    using (var repo = new Repository(@"D:\temp\Linux\linux-2.6"))
    {
        Console.WriteLine("merges {0}", repo.Commits.Count(commit => commit.ParentsCount > 1));
    }
}

I even tried to list all of them with the also passing following test

[Test]
public void CanListMergeCommits()
{
    using (var repo = new Repository(@"D:\temp\Linux\linux-2.6"))
    {
        var cs = repo.Commits.Where(c => c.ParentsCount > 1);

        foreach (var c in cs)
        {
            Console.WriteLine("{0} : {1} - {2}", c.Committer.When.ToString("o"), c.Sha, c.ParentsCount);            
        }
    }
}

As the output is pretty big, I pasted it into a Gist.

This has been checked against the current tip of vNext branch (libgit2/libgit2sharp@922d33c35e29f4a2ff749e7beea27144d065c741) on a Win 7 (x86) box. Both Debug and Release configurations have been tested.

psantosl commented 12 years ago

Hey

I was on a win7 64, but built my assemblies as 32 to make them work out of the box with the downloaded .zip of libgit2sharp I downloaded yesterday

I can send you the specific version later

El 26/02/2012, a las 17:25, "nulltoken" reply@reply.github.com escribió:

@psantosl Hum. I can't reproduce this issue :-/

Following test outputs merges 18653

[Test]
public void CanCountMergeCommits()
{
   using (var repo = new Repository(@"D:\temp\Linux\linux-2.6"))
   {
       Console.WriteLine("merges {0}", repo.Commits.Count(commit => commit.ParentsCount > 1));
   }
}

I even tried to list all of them with the also passing following test

[Test]
public void CanListMergeCommits()
{
   using (var repo = new Repository(@"D:\temp\Linux\linux-2.6"))
   {
       var cs = repo.Commits.Where(c => c.ParentsCount > 1);

       foreach (var c in cs)
       {
           Console.WriteLine("{0} : {1} - {2}", c.Committer.When.ToString("o"), c.Sha, c.ParentsCount);            
       }
   }
}

As the output is pretty big, I pasted it into a Gist.

This has been checked against the current tip of vNext branch (libgit2/libgit2sharp@922d33c35e29f4a2ff749e7beea27144d065c741) on a Win 7 (x86) box. Both Debug and Release configurations have been tested.

  • Which version of LibGit2Sharp did you use?
  • What is your OS?

Reply to this email directly or view it on GitHub: https://github.com/libgit2/libgit2sharp/issues/115#issuecomment-4182317

nulltoken commented 12 years ago

@psantosl

Could you try to repro this against

Thanks in advance.

nulltoken commented 12 years ago

@psantosl Have you had the time to reproduce this?

psantosl commented 12 years ago

Hi,

Sorry for the delay... I was traveling a lot in the last weeks (been in SF with @schacon too :P).

Ok, I downloaded and built the sources. Do I need to use NuGet? Can't I just download and build the sources on my tree without having to install anything?

I'm trying to get familiar with all this because we're working on a stronger sync.

nulltoken commented 12 years ago

Can't I just download and build the sources on my tree without having to install anything?

Of course you can!

I'd really like to ensure the 32/64bits version runs smoothly on a 64bits environment as I'd like to release it to as part of release v0.9.

Please keep me updated.

psantosl commented 12 years ago

Hi nulltoken,

I've just downloaded and built 1cb40daeab62551b44a964e2dce60bad098a0477 from https://github.com/nulltoken/libgit2sharp/tree/experimental/hybrid

And I'm getting exactly the same issue.

It makes me wonder whether my linux repo is broken or something... weird.

I tried with other repos and it seems to work fine.

nulltoken commented 12 years ago

And I'm getting exactly the same issue.

Let's try this with the CanListMergeCommits() test in one the comment above. Could you run it? When the exception occurs, please copy and share the stack trace.

If you convert the var cs = repo.Commits.Where(c => c.ParentsCount > 1); to a plain foreach as below (warning: untested code), are you able to isolate which commit causes the issue? If you run it several times, does it always fail when parsing the same commit?

int cs = 0;
foreach (Commit c in repo.Commits)
{
  try
  {
    if (c.ParentsCount > 1)
      cs++;
  }
  catch(Exception e)
  {
    Debugger.Break();
  }
}

It makes me wonder whether my linux repo is broken or something... weird.

Have you tried cloning the repo in a brand new folder? Do you get the same issue?

psantosl commented 12 years ago

The issue is in the enumerator, so your code doesn't catch it, but it is easy to get the stack trace:

cs: 11128 Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at LibGit2Sharp.Core.NativeMethods.git_revwalk_next(GitOid& oid, RevWalkerSafeHandle walker) at LibGit2Sharp.CommitCollection.CommitEnumerator.MoveNext() in c:\Users\pablo\wkspaces\libgit2\LibGit2Sharp\CommitCollection.cs:line 215 at libgit2test.Program.Main(String[] args) in C:\Users\pablo\wkspaces\libgit2test\Program.cs:line 20

nulltoken commented 12 years ago

The issue is in the enumerator, so your code doesn't catch it,

Damn! I thought it was related to the parsing of the commit. That's a totally different story. Moreover as the revwalk fails pretty "far" down the commit history, it might not be that easy to debug.

If you run your program several times, does it always fail with the same cs value?

Have you tried running it on a freshly cloned copy of the repo?

psantosl commented 12 years ago

Yes, it always fails at the same position.

Now I'll check if it fails with a clean one too...

psantosl commented 12 years ago

Tried on a freshly downloaded one:

git clone git://github.com/mirrors/linux-2.6.git Cloning into linux-2.6... remote: Counting objects: 2420414, done. remote: Compressing objects: 100% (451579/451579), done. remote: Total 2420414 (delta 2024530), reused 2324136 (delta 1945134) Receiving objects: 100% (2420414/2420414), 565.39 MiB | 682 KiB/s, done. Resolving deltas: 100% (2024530/2024530), done.

cs: 6195 Attempted to read or write protected memory. This is often an indication that ot her memory is corrupt. at LibGit2Sharp.Core.NativeMethods.git_revwalk_next(GitOid& oid, RevWalkerSafeHandle walker) at LibGit2Sharp.CommitCollection.CommitEnumerator.MoveNext() in c:\Users\pablo\wkspaces\libgit2\LibGit2Sharp\CommitCollection.cs:line 215 at libgit2test.Program.Main(String[] args) in C:\Users\pablo\wkspaces\libgit2test\Program.cs:line 19

nulltoken commented 12 years ago

Wow! I've finally reproduced the issue :)

psantosl commented 12 years ago

Great!!

El 30/03/2012, a las 15:50, "nulltoken" reply@reply.github.com escribió:

Wow! I've finally reproduced the issue :)


Reply to this email directly or view it on GitHub: https://github.com/libgit2/libgit2sharp/issues/115#issuecomment-4842764

nulltoken commented 12 years ago

@psantosl This looks like a libgit2 issue. An issue has been created (cf. libgit2/libgit2#614)

nulltoken commented 12 years ago

The fix has been done in libgit2 and is now available in LibGit2Sharp/vNext.

Cheers!