Skip to content

Commit

Permalink
Fix bugs with > 2 GB pack files
Browse files Browse the repository at this point in the history
  • Loading branch information
filipnavara committed Jul 28, 2021
1 parent bf2ade8 commit b9f2141
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Expand Up @@ -128,7 +128,7 @@ public override (long?, GitObjectId?) GetOffset(Span<byte> objectName, bool ends
{
// 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,
// which follows the table of 4-byte offset entries: "large offsets are encoded as an index into the next table with the msbit set."
offset = offset & 0x7FF;
offset = offset & 0x7FFFFFFF;

offsetBuffer = this.Value.Slice(offsetTableStart + 4 * objectCount + 8 * (int)offset, 8);
var offset64 = BinaryPrimitives.ReadInt64BigEndian(offsetBuffer);
Expand Down
6 changes: 3 additions & 3 deletions src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs
Expand Up @@ -44,7 +44,7 @@ public static Stream GetObject(GitPack pack, Stream stream, long offset, string
if (type == GitPackObjectType.OBJ_OFS_DELTA)
{
var baseObjectRelativeOffset = ReadVariableLengthInteger(stream);
var baseObjectOffset = (int)(offset - baseObjectRelativeOffset);
var baseObjectOffset = offset - baseObjectRelativeOffset;

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

private static int ReadVariableLengthInteger(Stream stream)
private static long ReadVariableLengthInteger(Stream stream)
{
int offset = -1;
long offset = -1;
int b;

do
Expand Down

0 comments on commit b9f2141

Please sign in to comment.