From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Dmitry V. Levin" <ldv@altlinux.org>,
"Shawn O. Pearce" <spearce@spearce.org>,
Git Mailing List <git@vger.kernel.org>, Jeff King <peff@peff.net>
Subject: Re: [PATCH 2/2] Fix the rename detection limit checking
Date: Fri, 14 Sep 2007 11:44:04 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.0.999.0709141132250.16478@woody.linux-foundation.org> (raw)
In-Reply-To: <alpine.LFD.0.999.0709141017450.16478@woody.linux-foundation.org>
On Fri, 14 Sep 2007, Linus Torvalds wrote:
>
> ... and we also make sure that we don't overflow when doing the matrix
> size calculation.
Side note: by "make sure", I don't really mean a total guarantee.
We could be even more careful here. In particular:
- we later do end up allocating the matrix with
sizeof(*mx) * num_create * num_src
and I didn't actually fix the overflow that is possible due to the
"sizeof(*mx)" multiplication.
- even after we've checked that not *both* of the source and destination
counts are larger than the rename_limit, we could still overflow the
multiplication in just the limit check.
.. but with the rename_limit being set to 100, in practice neither of
these are really even close to realistic (ie you'd need to have less than
100 new files, and deleted over twenty million files to overflow, or vice
versa).
So with a rename_limit of 100, it's all good (I'm pretty sure you'd have
*other* issues long before you'd hit the integer overflows on renames ;)
But if somebody sets the rename_limit to something bigger, it gets
increasingly easier to screw it up.
If somebody wants to be *really* careful, they'd need to do something like
unsigned long max;
/* This isn't going to overflow, since we limited 'rename_limit' */
max = rename_limit * rename_limit;
/*
* But we should also check that multiplying by "sizeof(*mx)"
* won't make it overlof either..
*/
while ((sizeof(*mx) * max) / sizeof(*mx) != max)
max >>= 1;
/*
* And then avoid multiplying "rename_dst_nr" and "rename_src_nr"
* together by turning it into a division instead
*/
if (max / rename_dst_nr > rename_src_nr)
goto cleanup;
but the patch I sent out was the "obvious" first one that at least avoided
the overflow for the triggerable case that Dmitry had, and as per above
likely in all reasonable cases...
Linus
next prev parent reply other threads:[~2007-09-14 18:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-05 23:49 [PATCH 1/2] git-commit: Disallow unchanged tree in non-merge mode Dmitry V. Levin
2007-09-06 2:25 ` Shawn O. Pearce
2007-09-06 10:16 ` Dmitry V. Levin
[not found] ` <20070909044648.GH18160@spearce.org>
[not found] ` <7vir6fjmuv.fsf@gitster.siamese.dyndns.org>
[not found] ` <20070913035137.GM3099@spearce.org>
[not found] ` <7vr6l2gxyw.fsf@gitster.siamese.dyndns.org>
[not found] ` <20070914000108.GE3619@basalt.office.altlinux.org>
[not found] ` <7vr6l2f6k1.fsf@gitster.siamese.dyndns.org>
[not found] ` <alpine.LFD.0.999.0709131850060.16478@woody.linux-foundation.org>
[not found] ` <20070914024303.GH3619@basalt.office.altlinux.org>
[not found] ` <alpine.LFD.0.999.0709132123570.16478@woody.linux-foundation.org>
2007-09-14 17:14 ` Linus Torvalds
2007-09-14 17:17 ` [PATCH 1/2] Fix "git diff" setup code Linus Torvalds
2007-09-14 17:39 ` [PATCH 2/2] Fix the rename detection limit checking Linus Torvalds
2007-09-14 18:44 ` Linus Torvalds [this message]
2007-09-14 18:49 ` Linus Torvalds
2007-09-14 18:19 ` [PATCH 1/2] Fix "git diff" setup code Junio C Hamano
2007-09-14 18:30 ` Linus Torvalds
2007-09-14 19:11 ` Junio C Hamano
2007-09-14 19:46 ` Linus Torvalds
[not found] ` <20070914050410.GA11402@coredump.intra.peff.net>
[not found] ` <alpine.LFD.0.999.0709132215250.16478@woody.linux-foundation.org>
2007-09-14 18:24 ` [PATCH 1/2] git-commit: Disallow unchanged tree in non-merge mode 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=alpine.LFD.0.999.0709141132250.16478@woody.linux-foundation.org \
--to=torvalds@linux-foundation.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ldv@altlinux.org \
--cc=peff@peff.net \
--cc=spearce@spearce.org \
/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).