Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs with > 2 GB pack files #634

Merged
merged 2 commits into from Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref: https://github.com/go-git/go-git/blob/master/plumbing/format/idxfile/idxfile.go#L146
Ref: https://git-scm.com/docs/pack-format

If the large offset chunk exists and the 31st bit is on, then removing that bit reveals the row in the large offsets containing the 8-byte offset of this object.


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;
filipnavara marked this conversation as resolved.
Show resolved Hide resolved

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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref: https://git-scm.com/docs/pack-format

Observation: length of each object is encoded in a variable length format and is not constrained to 32-bit or anything.

Example: Base offset is 4 000 000 000, delta relative offset would be 3 000 000 000. The computed delta offset would thus be 1 000 000 000. The number 3 000 000 000 must fit in the data type returned here.

int b;

do
Expand Down