diff options
author | Carlos Martín Nieto <carlosmn@github.com> | 2023-03-14 15:51:50 +0100 |
---|---|---|
committer | Carlos Martín Nieto <carlosmn@github.com> | 2023-03-14 15:57:49 +0100 |
commit | 62b9f803575d261348508c449f8e1698beebb115 (patch) | |
tree | 52515345cf195c8f2b4b33ed10691113d848b49d | |
parent | 8f8e805e3f37e49563c33a0c67fcf7f0d2e9101c (diff) | |
download | libgit2-62b9f803575d261348508c449f8e1698beebb115.tar.gz |
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.
-rw-r--r-- | src/libgit2/pack.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libgit2/pack.c b/src/libgit2/pack.c index c30801844..6e99d4b71 100644 --- a/src/libgit2/pack.c +++ b/src/libgit2/pack.c @@ -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) { struct git_pack_idx_header *hdr; - uint32_t version, nr, i, *index; + uint32_t version, i, *index; + uint64_t nr = 0; void *idx_map; size_t idx_size; struct stat st; @@ -246,7 +247,6 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p) version = 1; } - nr = 0; index = idx_map; if (version > 1) @@ -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 * for offsets larger than 2^31. */ - unsigned long min_size = 8 + (4 * 256) + (nr * (p->oid_size + 4 + 4)) + (p->oid_size * 2); - unsigned long max_size = min_size; + uint64_t min_size = 8 + (4 * 256) + (nr * (p->oid_size + 4 + 4)) + (p->oid_size * 2); + uint64_t max_size = min_size; if (nr) max_size += (nr - 1)*8; |