Skip to content

Commit af92a64

Browse files
pcloudsgitster
authored andcommitted
pack-objects: do not truncate result in-pack object size on 32-bit systems
A typical diff will not show what's going on and you need to see full functions. The core code is like this, at the end of of write_one() e->idx.offset = *offset; size = write_object(f, e, *offset); if (!size) { e->idx.offset = recursing; return WRITE_ONE_BREAK; } written_list[nr_written++] = &e->idx; /* make sure off_t is sufficiently large not to wrap */ if (signed_add_overflows(*offset, size)) die("pack too large for current definition of off_t"); *offset += size; Here we can see that the in-pack object size is returned by write_object (or indirectly by write_reuse_object). And it's used to calculate object offsets, which end up in the pack index file, generated at the end. If "size" overflows (on 32-bit sytems, unsigned long is 32-bit while off_t can be 64-bit), we got wrong offsets and produce incorrect .idx file, which may make it look like the .pack file is corrupted. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent da49a7d commit af92a64

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

builtin/pack-objects.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
341341
}
342342

343343
/* Return 0 if we will bust the pack-size limit */
344-
static unsigned long write_reuse_object(struct sha1file *f, struct object_entry *entry,
345-
unsigned long limit, int usable_delta)
344+
static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,
345+
unsigned long limit, int usable_delta)
346346
{
347347
struct packed_git *p = entry->in_pack;
348348
struct pack_window *w_curs = NULL;
@@ -415,11 +415,12 @@ static unsigned long write_reuse_object(struct sha1file *f, struct object_entry
415415
}
416416

417417
/* Return 0 if we will bust the pack-size limit */
418-
static unsigned long write_object(struct sha1file *f,
419-
struct object_entry *entry,
420-
off_t write_offset)
418+
static off_t write_object(struct sha1file *f,
419+
struct object_entry *entry,
420+
off_t write_offset)
421421
{
422-
unsigned long limit, len;
422+
unsigned long limit;
423+
off_t len;
423424
int usable_delta, to_reuse;
424425

425426
if (!pack_to_stdout)
@@ -491,7 +492,7 @@ static enum write_one_status write_one(struct sha1file *f,
491492
struct object_entry *e,
492493
off_t *offset)
493494
{
494-
unsigned long size;
495+
off_t size;
495496
int recursing;
496497

497498
/*

0 commit comments

Comments
 (0)