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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 24, 2017 at 13:26 UTC 2c5e2865cc3dfc053e71510415f479e165119d04
2 files changed +10 -2
builtin/pack-objects.c
+4 -2
@@ -239,7 +239,8 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
239 unsigned long limit, int usable_delta)
240 {
241 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];
244 unsigned hdrlen;
245 enum object_type type;
246 void *buf;
@@ -353,7 +354,8 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,
354 off_t offset;
355 enum object_type type = entry->type;
356 off_t datalen;
356 - unsigned char header[10], dheader[10];
357 + unsigned char header[MAX_PACK_OBJECT_HEADER],
358 + dheader[MAX_PACK_OBJECT_HEADER];
359 unsigned hdrlen;
360
361 if (entry->delta)
pack.h
+6
@@ -84,6 +84,12 @@ extern int verify_pack(struct packed_git *, verify_fn fn, struct progress *, uin
84 extern off_t write_pack_header(struct sha1file *f, uint32_t);
85 extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);
86 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
93 extern int encode_in_pack_object_header(unsigned char *hdr, int hdr_len,
94 enum object_type, uintmax_t);
95