Skip to content

Commit 62b9f80

Browse files
committed
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.
1 parent 8f8e805 commit 62b9f80

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/libgit2/pack.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ static void pack_index_free(struct git_pack_file *p)
200200
static int pack_index_check_locked(const char *path, struct git_pack_file *p)
201201
{
202202
struct git_pack_idx_header *hdr;
203-
uint32_t version, nr, i, *index;
203+
uint32_t version, i, *index;
204+
uint64_t nr = 0;
204205
void *idx_map;
205206
size_t idx_size;
206207
struct stat st;
@@ -246,7 +247,6 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
246247
version = 1;
247248
}
248249

249-
nr = 0;
250250
index = idx_map;
251251

252252
if (version > 1)
@@ -287,8 +287,8 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
287287
* variable sized table containing 8-byte entries
288288
* for offsets larger than 2^31.
289289
*/
290-
unsigned long min_size = 8 + (4 * 256) + (nr * (p->oid_size + 4 + 4)) + (p->oid_size * 2);
291-
unsigned long max_size = min_size;
290+
uint64_t min_size = 8 + (4 * 256) + (nr * (p->oid_size + 4 + 4)) + (p->oid_size * 2);
291+
uint64_t max_size = min_size;
292292

293293
if (nr)
294294
max_size += (nr - 1)*8;

0 commit comments

Comments
 (0)