Skip to content

Commit 211c61c

Browse files
pcloudsgitster
authored andcommitted
pack-objects: pass length to check_pack_crc() without truncation
On 32 bit systems with large file support, unsigned long is 32-bit while the two offsets in the subtraction expression (pack-objects has the exact same expression as in sha1_file.c but not shown in diff) are in 64-bit. If an in-pack object is larger than 2^32 len/datalen is truncated and we get a misleading "error: bad packed object CRC for ..." as a result. Use off_t for len and datalen. check_pack_crc() already accepts this argument as off_t and can deal with 4+ GB. Noticed-by: Christoph Michelbach <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b65a8d commit 211c61c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ static unsigned long write_reuse_object(struct sha1file *f, struct object_entry
349349
struct revindex_entry *revidx;
350350
off_t offset;
351351
enum object_type type = entry->type;
352-
unsigned long datalen;
352+
off_t datalen;
353353
unsigned char header[10], dheader[10];
354354
unsigned hdrlen;
355355

sha1_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
22822282

22832283
if (do_check_packed_object_crc && p->index_version > 1) {
22842284
struct revindex_entry *revidx = find_pack_revindex(p, obj_offset);
2285-
unsigned long len = revidx[1].offset - obj_offset;
2285+
off_t len = revidx[1].offset - obj_offset;
22862286
if (check_pack_crc(p, &w_curs, obj_offset, len, revidx->nr)) {
22872287
const unsigned char *sha1 =
22882288
nth_packed_object_sha1(p, revidx->nr);

0 commit comments

Comments
 (0)