From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: "René Scharfe" <l.s.r@web.de>,
"Ori Bernstein" <ori@eigenstate.org>,
git@vger.kernel.org
Subject: Re: [PATCH] Avoid infinite loop in malformed packfiles
Date: Mon, 24 Aug 2020 13:38:35 -0700 [thread overview]
Message-ID: <xmqq5z974w50.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20200824201208.GA706849@coredump.intra.peff.net> (Jeff King's message of "Mon, 24 Aug 2020 16:12:08 -0400")
Jeff King <peff@peff.net> writes:
> I think it may be worth making this a configurable value
> (core.maxDeltaDepth or something). Nobody would generally need to tweak
> it, but it would give an escape hatch for getting people out of a broken
> situation ("git -c core.maxDeltaDepth=50000 repack" or similar).
... meaning "the pack I have has overlong delta chains to read, and
I am running repack to cut these chains down to more manageable
level"? Makes sense.
As it may be a bit tricky to figure out where we should read such a
configuration for those who are new to our codebase, here is an
illustration to give a starting point. Docs and tests are probably
needed, too.
cache.h | 1 +
config.c | 5 +++++
environment.c | 1 +
packfile.c | 6 ++++++
4 files changed, 13 insertions(+)
diff --git a/cache.h b/cache.h
index 0290849c19..b59d43f0ec 100644
--- a/cache.h
+++ b/cache.h
@@ -919,6 +919,7 @@ extern int minimum_abbrev, default_abbrev;
extern int ignore_case;
extern int assume_unchanged;
extern int prefer_symlink_refs;
+extern int max_allowed_delta_depth;
extern int warn_ambiguous_refs;
extern int warn_on_object_refname_ambiguity;
extern const char *apply_default_whitespace;
diff --git a/config.c b/config.c
index 2b79fe76ad..5f9114f847 100644
--- a/config.c
+++ b/config.c
@@ -1197,6 +1197,11 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
return 0;
}
+ if (!strcmp(var, "core.maxalloweddeltadepth")) {
+ max_allowed_delta_depth = git_config_int(var, value);
+ return 0;
+ }
+
if (!strcmp(var, "core.logallrefupdates")) {
if (value && !strcasecmp(value, "always"))
log_all_ref_updates = LOG_REFS_ALWAYS;
diff --git a/environment.c b/environment.c
index 52e0c979ba..d3f9a10799 100644
--- a/environment.c
+++ b/environment.c
@@ -27,6 +27,7 @@ int minimum_abbrev = 4, default_abbrev = -1;
int ignore_case;
int assume_unchanged;
int prefer_symlink_refs;
+int max_allowed_delta_depth = 10000;
int is_bare_repository_cfg = -1; /* unspecified */
int warn_ambiguous_refs = 1;
int warn_on_object_refname_ambiguity = 1;
diff --git a/packfile.c b/packfile.c
index 6ab5233613..2ea24a19dd 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1715,6 +1715,12 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
break;
}
+ if (max_allowed_delta_depth < delta_stack_nr) {
+ error("overlong delta chain at offset %"PRIuMAX" from %s",
+ (uintmax_t)curpos, p->pack_name);
+ goto out;
+ }
+
/* push object, proceed to base */
if (delta_stack_nr >= delta_stack_alloc
&& delta_stack == small_delta_stack) {
next prev parent reply other threads:[~2020-08-24 20:38 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-23 0:52 [PATCH] Avoid infinite loop in malformed packfiles Ori Bernstein
2020-08-23 2:52 ` ori
2020-08-23 3:08 ` Eric Sunshine
2020-08-23 3:11 ` Ori Bernstein
2020-08-23 6:26 ` René Scharfe
2020-08-23 20:41 ` Ori Bernstein
2020-08-24 16:06 ` René Scharfe
2020-08-24 20:12 ` Jeff King
2020-08-24 20:38 ` Junio C Hamano [this message]
2020-08-24 20:52 ` Jeff King
2020-08-24 21:22 ` Junio C Hamano
2020-08-30 3:33 ` ori
2020-08-30 10:56 ` René Scharfe
2020-08-30 16:15 ` Junio C Hamano
2020-08-31 9:29 ` Jeff King
2020-08-31 16:32 ` Junio C Hamano
2020-08-31 19:23 ` Jeff King
2020-08-31 16:50 ` ori
2020-08-24 17:33 ` Junio C Hamano
2020-08-24 20:30 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq5z974w50.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
--cc=ori@eigenstate.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).