diff --git a/src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs b/src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs index 6a55fe77..0c14a314 100644 --- a/src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs +++ b/src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs @@ -136,14 +136,24 @@ public void TryGetObjectTest() using (SHA1 sha = SHA1.Create()) { Assert.True(gitPack.TryGetObject(GitObjectId.Parse("f5b401f40ad83f13030e946c9ea22cb54cb853cd"), "commit", out Stream commitStream)); - - // This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file. - var zlibStream = Assert.IsType(commitStream); - var deflateStream = Assert.IsType(zlibStream.BaseStream); - var pooledStream = Assert.IsType(deflateStream.BaseStream); - - Assert.Equal(222, commitStream.Length); - Assert.Equal("/zgldANj+jvgOwlecnOKylZDVQg=", Convert.ToBase64String(sha.ComputeHash(commitStream))); + using (commitStream) + { + // This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file. + var zlibStream = Assert.IsType(commitStream); + var deflateStream = Assert.IsType(zlibStream.BaseStream); + + if (IntPtr.Size > 4) + { + var pooledStream = Assert.IsType(deflateStream.BaseStream); + } + else + { + var directAccessStream = Assert.IsType(deflateStream.BaseStream); + } + + Assert.Equal(222, commitStream.Length); + Assert.Equal("/zgldANj+jvgOwlecnOKylZDVQg=", Convert.ToBase64String(sha.ComputeHash(commitStream))); + } } } diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs b/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs index eff2eaf8..5d19128d 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs @@ -205,7 +205,17 @@ public Stream GetObject(long offset, string objectType) } var packStream = this.GetPackStream(); - Stream objectStream = GitPackReader.GetObject(this, packStream, offset, objectType, packObjectType); + Stream objectStream; + + try + { + objectStream = GitPackReader.GetObject(this, packStream, offset, objectType, packObjectType); + } + catch + { + packStream.Dispose(); + throw; + } return this.cache.Add(offset, objectStream); }