git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH 1/3] index-pack: add --max-input-size=<size> option

From
Christian Couder <christian.couder@gmail.com>
Date
Aug 15, 2016, 19:57 UTC
Message-ID
<20160815195729.16826-2-chriscool@tuxfamily.org>
In-Reply-To
<20160815195729.16826-1-chriscool@tuxfamily.org>
From: Jeff King <peff@peff.net>

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>
---
 builtin/index-pack.c | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 1d2ea58..1fd60bd 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -87,6 +87,7 @@ static struct progress *progress;
 static unsigned char input_buffer[4096];
 static unsigned int input_offset, input_len;
 static off_t consumed_bytes;
+static off_t max_input_size;
 static unsigned deepest_delta;
 static git_SHA_CTX input_ctx;
 static uint32_t input_crc32;
@@ -297,6 +298,8 @@ static void use(int bytes)
 	if (signed_add_overflows(consumed_bytes, bytes))
 		die(_("pack too large for current definition of off_t"));
 	consumed_bytes += bytes;
+	if (max_input_size && consumed_bytes > max_input_size)
+		die(_("pack exceeds maximum allowed size"));
 }
 
 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)
 					opts.off32_limit = strtoul(c+1, &c, 0);
 				if (*c || opts.off32_limit & 0x80000000)
 					die(_("bad %s"), arg);
+			} else if (skip_prefix(arg, "--max-input-size=", &arg)) {
+				max_input_size = strtoul(arg, NULL, 10);
 			} else
 				usage(index_pack_usage);
 			continue;
-- 
2.10.0.rc0.4.g229e32c.dirty
Previous: Christian CouderNext: Jeff King
Message 2 of 11 in “limit the size of the packs we receive”
  1. 0/3 limit the size of the packs we receiveChristian Couder, Aug 15, 2016
  2. 1/3 index-pack: add --max-input-size=<size> optionChristian Couder, Aug 15, 2016
  3. Jeff KingAug 15, 2016
  4. 2/3 unpack-objects: add --max-input-size=<size> optionChristian Couder, Aug 15, 2016
  5. Jeff KingAug 15, 2016
  6. 3/3 receive-pack: allow a maximum input size to be specifiedChristian Couder, Aug 15, 2016
  7. Jeff KingAug 15, 2016
  8. Junio C HamanoAug 15, 2016
  9. Jeff KingAug 16, 2016
  10. Christian CouderAug 16, 2016
  11. Jeff KingAug 16, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.