Skip to content

Commit fa7c948

Browse files
authored
Merge pull request #634 from filipnavara/large-pack-offsets
Fix bugs with > 2 GB pack files
2 parents f90c41c + a7eaba9 commit fa7c948

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/NerdBank.GitVersioning/ManagedGit/GitPackIndexMappedReader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public override (long?, GitObjectId?) GetOffset(Span<byte> objectName, bool ends
128128
{
129129
// If the first bit of the offset address is set, the offset is stored as a 64-bit value in the table of 8-byte offset entries,
130130
// which follows the table of 4-byte offset entries: "large offsets are encoded as an index into the next table with the msbit set."
131-
offset = offset & 0x7FF;
131+
offset = offset & 0x7FFFFFFF;
132132

133133
offsetBuffer = this.Value.Slice(offsetTableStart + 4 * objectCount + 8 * (int)offset, 8);
134134
var offset64 = BinaryPrimitives.ReadInt64BigEndian(offsetBuffer);

src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static Stream GetObject(GitPack pack, Stream stream, long offset, string
4444
if (type == GitPackObjectType.OBJ_OFS_DELTA)
4545
{
4646
var baseObjectRelativeOffset = ReadVariableLengthInteger(stream);
47-
var baseObjectOffset = (int)(offset - baseObjectRelativeOffset);
47+
long baseObjectOffset = offset - baseObjectRelativeOffset;
4848

4949
var deltaStream = new ZLibStream(stream, decompressedSize);
5050
var baseObjectStream = pack.GetObject(baseObjectOffset, objectType);
@@ -98,9 +98,9 @@ private static (GitPackObjectType, long) ReadObjectHeader(Stream stream)
9898
return (type, length);
9999
}
100100

101-
private static int ReadVariableLengthInteger(Stream stream)
101+
private static long ReadVariableLengthInteger(Stream stream)
102102
{
103-
int offset = -1;
103+
long offset = -1;
104104
int b;
105105

106106
do

0 commit comments

Comments
 (0)