index-pack: add --max-input-size=<size> option
When receiving a pack-file, it can be useful to abort the `git index-pack`, if the pack-file is too big. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Aug 24, 2016 at 20:41 UTC
411481be6f27fb1ae8e2263d1e686357226391a3
2 files changed
+7
Documentation/git-index-pack.txt
+2
@@ -87,6 +87,8 @@ OPTIONS
87
Specifying 0 will cause Git to auto-detect the number of CPU's
88
and use maximum 3 threads.
89
90
+--max-input-size=<size>::
91
+ Die, if the pack is larger than <size>.
92
93
Note
94
----
builtin/index-pack.c
+5
@@ -87,6 +87,7 @@ static struct progress *progress;
87
static unsigned char input_buffer[4096];
88
static unsigned int input_offset, input_len;
89
static off_t consumed_bytes;
90
+static off_t max_input_size;
91
static unsigned deepest_delta;
92
static git_SHA_CTX input_ctx;
93
static uint32_t input_crc32;
@@ -297,6 +298,8 @@ static void use(int bytes)
298
if (signed_add_overflows(consumed_bytes, bytes))
299
die(_("pack too large for current definition of off_t"));
300
consumed_bytes += bytes;
301
+ if (max_input_size && consumed_bytes > max_input_size)
302
+ die(_("pack exceeds maximum allowed size"));
303
}
304
305
static const char *open_pack_file(const char *pack_name)
@@ -1714,6 +1717,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1717
opts.off32_limit = strtoul(c+1, &c, 0);
1718
if (*c || opts.off32_limit & 0x80000000)
1719
die(_("bad %s"), arg);
1720
+ } else if (skip_prefix(arg, "--max-input-size=", &arg)) {
1721
+ max_input_size = strtoumax(arg, NULL, 10);
1722
} else
1723
usage(index_pack_usage);
1724
continue;