Commit 62b9f803 by Carlos Martín Nieto

pack: use 64 bits for the number of objects

Keeping it as a 32-bit value means the min size calculation overflows or gets
truncated which can lead to issues with large packfiles.
parent 8f8e805e
...@@ -200,7 +200,8 @@ static void pack_index_free(struct git_pack_file *p) ...@@ -200,7 +200,8 @@ static void pack_index_free(struct git_pack_file *p)
static int pack_index_check_locked(const char *path, struct git_pack_file *p) static int pack_index_check_locked(const char *path, struct git_pack_file *p)
{ {
struct git_pack_idx_header *hdr; struct git_pack_idx_header *hdr;
uint32_t version, nr, i, *index; uint32_t version, i, *index;
uint64_t nr = 0;
void *idx_map; void *idx_map;
size_t idx_size; size_t idx_size;
struct stat st; struct stat st;
...@@ -246,7 +247,6 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p) ...@@ -246,7 +247,6 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
version = 1; version = 1;
} }
nr = 0;
index = idx_map; index = idx_map;
if (version > 1) if (version > 1)
...@@ -287,8 +287,8 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p) ...@@ -287,8 +287,8 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
* variable sized table containing 8-byte entries * variable sized table containing 8-byte entries
* for offsets larger than 2^31. * for offsets larger than 2^31.
*/ */
unsigned long min_size = 8 + (4 * 256) + (nr * (p->oid_size + 4 + 4)) + (p->oid_size * 2); uint64_t min_size = 8 + (4 * 256) + (nr * (p->oid_size + 4 + 4)) + (p->oid_size * 2);
unsigned long max_size = min_size; uint64_t max_size = min_size;
if (nr) if (nr)
max_size += (nr - 1)*8; max_size += (nr - 1)*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