unpack-objects: add --max-input-size=<size> option
When receiving a pack-file, it can be useful to abort the `git unpack-objects`, if the pack-file is too big. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Aug 24, 2016 at 20:41 UTC
5ad218673328262839542b841b505c78132857e7
2 files changed
+10
Documentation/git-unpack-objects.txt
+3
@@ -44,6 +44,9 @@ OPTIONS
44
--strict::
45
Don't write objects with broken content or links.
46
47
+--max-input-size=<size>::
48
+ Die, if the pack is larger than <size>.
49
+
50
GIT
51
---
52
Part of the linkgit:git[1] suite
builtin/unpack-objects.c
+7
@@ -19,6 +19,7 @@ static const char unpack_usage[] = "git unpack-objects [-n] [-q] [-r] [--strict]
19
static unsigned char buffer[4096];
20
static unsigned int offset, len;
21
static off_t consumed_bytes;
22
+static off_t max_input_size;
23
static git_SHA_CTX ctx;
24
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
25
@@ -87,6 +88,8 @@ static void use(int bytes)
88
if (signed_add_overflows(consumed_bytes, bytes))
89
die("pack too large for current definition of off_t");
90
consumed_bytes += bytes;
91
+ if (max_input_size && consumed_bytes > max_input_size)
92
+ die(_("pack exceeds maximum allowed size"));
93
}
94
95
static void *get_data(unsigned long size)
@@ -550,6 +553,10 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
553
len = sizeof(*hdr);
554
continue;
555
}
556
+ if (skip_prefix(arg, "--max-input-size=", &arg)) {
557
+ max_input_size = strtoumax(arg, NULL, 10);
558
+ continue;
559
+ }
560
usage(unpack_usage);
561
}
562