Skip to content

Commit 2c5e286

Browse files
peffgitster
authored andcommitted
pack.h: define largest possible encoded object size
Several callers use fixed buffers for storing the pack object header, and they've picked 10 as a magic number. This is reasonable, since it handles objects up to 2^67. But let's give them a constant so it's clear that the number isn't pulled out of thin air. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7202a6f commit 2c5e286

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

builtin/pack-objects.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
239239
unsigned long limit, int usable_delta)
240240
{
241241
unsigned long size, datalen;
242-
unsigned char header[10], dheader[10];
242+
unsigned char header[MAX_PACK_OBJECT_HEADER],
243+
dheader[MAX_PACK_OBJECT_HEADER];
243244
unsigned hdrlen;
244245
enum object_type type;
245246
void *buf;
@@ -353,7 +354,8 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,
353354
off_t offset;
354355
enum object_type type = entry->type;
355356
off_t datalen;
356-
unsigned char header[10], dheader[10];
357+
unsigned char header[MAX_PACK_OBJECT_HEADER],
358+
dheader[MAX_PACK_OBJECT_HEADER];
357359
unsigned hdrlen;
358360

359361
if (entry->delta)

pack.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ extern int verify_pack(struct packed_git *, verify_fn fn, struct progress *, uin
8484
extern off_t write_pack_header(struct sha1file *f, uint32_t);
8585
extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);
8686
extern char *index_pack_lockfile(int fd);
87+
88+
/*
89+
* The "hdr" output buffer should be at least this big, which will handle sizes
90+
* up to 2^67.
91+
*/
92+
#define MAX_PACK_OBJECT_HEADER 10
8793
extern int encode_in_pack_object_header(unsigned char *hdr, int hdr_len,
8894
enum object_type, uintmax_t);
8995

0 commit comments

Comments
 (0)