add overflow tests on pack offset variables
Change a few size and offset variables to more appropriate type, then add overflow tests on those offsets. This prevents any bad data to be generated/processed if off_t happens to not be large enough to handle some big packs. Better be safe than sorry. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
committed by
Junio C Hamano
parent
8723f21626
commit
d7dd02231f
@ -369,7 +369,7 @@ static int revalidate_loose_object(struct object_entry *entry,
|
||||
return check_loose_inflate(map, mapsize, size);
|
||||
}
|
||||
|
||||
static off_t write_object(struct sha1file *f,
|
||||
static unsigned long write_object(struct sha1file *f,
|
||||
struct object_entry *entry)
|
||||
{
|
||||
unsigned long size;
|
||||
@ -503,16 +503,23 @@ static off_t write_one(struct sha1file *f,
|
||||
struct object_entry *e,
|
||||
off_t offset)
|
||||
{
|
||||
unsigned long size;
|
||||
|
||||
/* offset is non zero if object is written already. */
|
||||
if (e->offset || e->preferred_base)
|
||||
/* offset starts from header size and cannot be zero
|
||||
* if it is written already.
|
||||
*/
|
||||
return offset;
|
||||
/* if we are deltified, write out its base object first. */
|
||||
|
||||
/* if we are deltified, write out base object first. */
|
||||
if (e->delta)
|
||||
offset = write_one(f, e->delta, offset);
|
||||
|
||||
e->offset = offset;
|
||||
return offset + write_object(f, e);
|
||||
size = write_object(f, e);
|
||||
|
||||
/* make sure off_t is sufficiently large not to wrap */
|
||||
if (offset > offset + size)
|
||||
die("pack too large for current definition of off_t");
|
||||
return offset + size;
|
||||
}
|
||||
|
||||
static void write_pack_file(void)
|
||||
|
||||
Reference in New Issue
Block a user