Fix native heap corruption in GitPackIndexMappedReaderTests#1360
Merged
Conversation
The test was double-closing the FileStream: once via the explicit 'using' block on the FileStream variable, and again inside GitPackIndexMappedReader.Dispose() which calls MemoryMappedFile.Dispose() (created with leaveOpen: false). On Linux/net10 this caused non-deterministic native heap corruption (free(): invalid pointer, double free or corruption, malloc_consolidate(): invalid chunk size) that crashed the test host with exit code 134 — the pattern seen in 4 consecutive ubuntu-24.04 CI failures. Additionally, the GetOffsetFromPartialTest assertions compared a GitObjectId? (Nullable<GitObjectId>) against a GitObjectId value type using Assert.Equal. On .NET Framework (net472/x86) the boxed struct equality check could fail even when the underlying bytes matched. Switch to comparing the string representation instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jun 19, 2026
This was referenced Jun 25, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The ubuntu-24.04 CI build has been failing non-deterministically with native heap corruption errors during test execution:
free(): invalid pointer(runs #24475017484, #24474758609)double free or corruption (out)(run #24474464353)malloc_consolidate(): invalid chunk size(run #24475399839)All four failures show the test host crashing with exit code 134 (SIGABRT) and zero actual test failures — the process dies during cleanup. A separate Windows build (#24473836691) also failed in the same test class (
GetOffsetFromPartialTest) with a value-equality assertion failure on net472/x86.Root Cause
Double-free of FileStream:
GitPackIndexMappedReaderTestswrapped theFileStreamin an explicitusingblock and passed it toGitPackIndexMappedReader, which takes ownership viaMemoryMappedFile.CreateFromFile(..., leaveOpen: false). When the outerusingblock then tried to dispose the already-closed stream, the native file handle was freed twice — causing heap corruption on Linux.Nullable struct equality:
GetOffsetFromPartialTestcomparedGitObjectId?(boxed nullable) withGitObjectId(value type) usingAssert.Equal. On .NET Framework x86, the boxing path could produce a false negative even when the underlying bytes matched.Fix
usingonFileStreamsoGitPackIndexMappedReaderis the sole ownerobjectId.Value.ToString()instead of comparing boxed nullable structs