From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [RFC/PATCH] cache-tree: avoid infinite loop on zero-entry tree
Date: Wed, 29 Oct 2014 11:50:12 -0700 [thread overview]
Message-ID: <xmqqppdayal7.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20141029171158.GA32188@peff.net> (Jeff King's message of "Wed, 29 Oct 2014 13:11:58 -0400")
Jeff King <peff@peff.net> writes:
> I'm a little iffy on this just because it is fixing one particular bug,
> and I am sure there are probably a bunch of other ways to have a bogus
> index. Fundamentally, I think we pretty much trust that the index was
> not maliciously generated (unlike packfiles, for instance, which can
> come from elsewhere). Still, this is one step closer to safe, and the
> bug was seen in the wild, so maybe it is worth doing.
Is it cheap to sanity-check the input when we map in the cache-tree
upon read_cache()? Then we can just invalidate the cache-tree,
either in its entirety (easy) or just the bogus subpart (maybe not
worth doing).
> We could alternatively (or in addition) reject 0-entry cache trees when
> reading them from disk. The trick, though, is that it is not just
> records with 0 entries, but ones where the sum of the entries and
> subtree entries is 0. Given that it is not something we expect to
> happen, it is easier to catch it here. And we know there can be no
> regressions for missed corner cases, because the case we are catching
> here would _always_ have gone into an infinite loop before this patch.
OK. I wonder if we can instead die here but propagate the error
back up the callchain and have the ultimate caller rebuild the cache
tree without paying attention to the existing data that we now know
is bogus.
> cache-tree.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/cache-tree.c b/cache-tree.c
> index 215202c..32772b9 100644
> --- a/cache-tree.c
> +++ b/cache-tree.c
> @@ -303,6 +303,8 @@ static int update_one(struct cache_tree *it,
> flags);
> if (subcnt < 0)
> return subcnt;
> + if (!subcnt)
> + die("index cache-tree records empty sub-tree");
> i += subcnt;
> sub->count = subcnt; /* to be used in the next loop */
> *skip_count += subskip;
next prev parent reply other threads:[~2014-10-29 18:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-29 17:11 [RFC/PATCH] cache-tree: avoid infinite loop on zero-entry tree Jeff King
2014-10-29 18:50 ` Junio C Hamano [this message]
2014-10-29 18:52 ` Jeff King
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqppdayal7.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.