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

Re: [PATCH 2/2] Fix the rename detection limit checking

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Sep 14, 2007, 18:44 UTC
Message-ID
<alpine.LFD.0.999.0709141132250.16478@woody.linux-foundation.org>
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
Previous: Linus TorvaldsNext: Linus Torvalds
Message 7 of 13 in “git-commit: Disallow unchanged tree in non-merge mode”
  1. 1/2 git-commit: Disallow unchanged tree in non-merge modeDmitry V. Levin, Sep 5, 2007
  2. Shawn O. PearceSep 6, 2007
  3. Dmitry V. LevinSep 6, 2007
  4. Linus TorvaldsSep 14, 2007
  5. 1/2 Fix "git diff" setup codeLinus Torvalds, Sep 14, 2007
  6. 2/2 Fix the rename detection limit checkingLinus Torvalds, Sep 14, 2007
  7. Linus TorvaldsSep 14, 2007
  8. Linus TorvaldsSep 14, 2007
  9. Junio C HamanoSep 14, 2007
  10. Linus TorvaldsSep 14, 2007
  11. Junio C HamanoSep 14, 2007
  12. Linus TorvaldsSep 14, 2007
  13. Junio C HamanoSep 14, 2007

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.