Skip to content

Commit 1b929b3

Browse files
authored
Merge pull request libgit2#6530 from libgit2/cmn/pack-index-64
pack: use 64 bits for the number of objects
2 parents 8f8e805 + 1d57344 commit 1b929b3

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/libgit2/pack.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ 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, nr = 0, i, *index;
204204
void *idx_map;
205205
size_t idx_size;
206206
struct stat st;
@@ -246,7 +246,6 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
246246
version = 1;
247247
}
248248

249-
nr = 0;
250249
index = idx_map;
251250

252251
if (version > 1)
@@ -269,7 +268,7 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
269268
* - 20/32-byte SHA of the packfile
270269
* - 20/32-byte SHA file checksum
271270
*/
272-
if (idx_size != (4 * 256 + (nr * (p->oid_size + 4)) + (p->oid_size * 2))) {
271+
if (idx_size != (4 * 256 + ((uint64_t) nr * (p->oid_size + 4)) + (p->oid_size * 2))) {
273272
git_futils_mmap_free(&p->index_map);
274273
return packfile_error("index is corrupted");
275274
}
@@ -287,8 +286,8 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p)
287286
* variable sized table containing 8-byte entries
288287
* for offsets larger than 2^31.
289288
*/
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;
289+
uint64_t min_size = 8 + (4 * 256) + ((uint64_t)nr * (p->oid_size + 4 + 4)) + (p->oid_size * 2);
290+
uint64_t max_size = min_size;
292291

293292
if (nr)
294293
max_size += (nr - 1)*8;

0 commit comments

Comments
 (0)