Commit 1bbe0dd8 by Carlos Martín Nieto

pack: cast the number of objects to size_t

Similar to a previous change where we had to change the casting when loading the
index file, we also need to make sure we don't restrict the numbers to 32-bit
when looking up objects in packfiles.

This was done about three years ago in git itself, but we never got he update in
this library.
parent f041a94e
......@@ -1268,13 +1268,13 @@ static off64_t nth_packed_object_offset_locked(struct git_pack_file *p, uint32_t
end = index + p->index_map.len;
index += 4 * 256;
if (p->index_version == 1)
return ntohl(*((uint32_t *)(index + (p->oid_size + 4) * n)));
return ntohl(*((uint32_t *)(index + (p->oid_size + 4) * (size_t) n)));
index += 8 + p->num_objects * (p->oid_size + 4);
index += 8 + (size_t) p->num_objects * (p->oid_size + 4);
off32 = ntohl(*((uint32_t *)(index + 4 * n)));
if (!(off32 & 0x80000000))
return off32;
index += p->num_objects * 4 + (off32 & 0x7fffffff) * 8;
index += (size_t) p->num_objects * 4 + (off32 & 0x7fffffff) * 8;
/* Make sure we're not being sent out of bounds */
if (index >= end - 8)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment