diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 0d03cb442d..4b8d86e0ad 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1597,7 +1597,7 @@ static void read_v2_anomalous_offsets(struct packed_git *p, /* The address of the 4-byte offset table */ idx1 = (((const uint32_t *)((const uint8_t *)p->index_data + p->crc_offset)) - + p->num_objects /* CRC32 table */ + + (size_t)p->num_objects /* CRC32 table */ ); /* The address of the 8-byte offset table */ diff --git a/pack-check.c b/pack-check.c index dad6d8ae7f..db3adf8781 100644 --- a/pack-check.c +++ b/pack-check.c @@ -39,7 +39,7 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, } while (len); index_crc = p->index_data; - index_crc += 2 + 256 + p->num_objects * (the_hash_algo->rawsz/4) + nr; + index_crc += 2 + 256 + (size_t)p->num_objects * (the_hash_algo->rawsz/4) + nr; return data_crc != ntohl(*index_crc); } diff --git a/pack-revindex.c b/pack-revindex.c index d28a7e43d0..ecdde39cf4 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -130,7 +130,7 @@ static void create_pack_revindex(struct packed_git *p) if (p->index_version > 1) { const uint32_t *off_32 = - (uint32_t *)(index + 8 + p->num_objects * (hashsz + 4)); + (uint32_t *)(index + 8 + (size_t)p->num_objects * (hashsz + 4)); const uint32_t *off_64 = off_32 + p->num_objects; for (i = 0; i < num_ent; i++) { const uint32_t off = ntohl(*off_32++); diff --git a/packfile.c b/packfile.c index 0929ebe4fc..a72c2a261f 100644 --- a/packfile.c +++ b/packfile.c @@ -148,7 +148,7 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map, * - hash of the packfile * - file checksum */ - if (idx_size != 4 * 256 + nr * (hashsz + 4) + hashsz + hashsz) + if (idx_size != 4 * 256 + (size_t)nr * (hashsz + 4) + hashsz + hashsz) return error("wrong index v1 file size in %s", path); } else if (version == 2) { /* @@ -164,10 +164,10 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map, * variable sized table containing 8-byte entries * for offsets larger than 2^31. */ - unsigned long min_size = 8 + 4*256 + nr*(hashsz + 4 + 4) + hashsz + hashsz; + unsigned long min_size = 8 + 4*256 + (size_t)nr*(hashsz + 4 + 4) + hashsz + hashsz; unsigned long max_size = min_size; if (nr) - max_size += (nr - 1)*8; + max_size += ((size_t)nr - 1)*8; if (idx_size < min_size || idx_size > max_size) return error("wrong index v2 file size in %s", path); if (idx_size != min_size && @@ -1933,14 +1933,14 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n) const unsigned int hashsz = the_hash_algo->rawsz; index += 4 * 256; if (p->index_version == 1) { - return ntohl(*((uint32_t *)(index + (hashsz + 4) * n))); + return ntohl(*((uint32_t *)(index + (hashsz + 4) * (size_t)n))); } else { uint32_t off; - index += 8 + p->num_objects * (hashsz + 4); + index += 8 + (size_t)p->num_objects * (hashsz + 4); off = ntohl(*((uint32_t *)(index + 4 * n))); if (!(off & 0x80000000)) return off; - index += p->num_objects * 4 + (off & 0x7fffffff) * 8; + index += (size_t)p->num_objects * 4 + (off & 0x7fffffff) * 8; check_pack_index_ptr(p, index); return get_be64(index); }