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

Broken PPC sha1.. (Re: Figured out how to get Mozilla into git)

From
Linus Torvalds <torvalds@osdl.org>
Date
Jun 18, 2006, 22:51 UTC
Message-ID
<Pine.LNX.4.64.0606181543270.5498@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0606181532130.5498@g5.osdl.org>
On Sun, 18 Jun 2006, Linus Torvalds wrote:
Show 14 quoted lines
> 
> On Mon, 19 Jun 2006, Martin Langhoff wrote:
> > 
> > No problems here with my latest import run. fsck-objects --full comes
> > clean, takes 14m:
> >
> > /usr/bin/time git-fsck-objects --full
> > 737.22user 38.79system 14:09.40elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
> > 0inputs+0outputs (20807major+19483471minor)pagefaults 0swaps
> 
> It takes much less than that for me: 
> 
> 	408.40user 32.56system 7:22.07elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
> 	0inputs+0outputs (145major+13455672minor)pagefaults 0swaps

Ok, re-building the thing with MOZILLA_SHA1=1 rather than my default PPC_SHA1=1 fixes the problem. I no longer get that "SHA1 mismatch with itself" on the pack-file.

Sadly, it also takes a _lot_ longer to fsck.

Paul - I think the ppc SHA1_Update() overflows in 32 bits, when the length of the memory area to be checksummed is huge.

In particular, the pack-file is 535MB in size, and the way we check the SHA1 checksum is by just mapping it all, doing a single SHA1_Update() over the whole pack-file, and comparing the end result with the internal SHA1 at the end of the pack-file.

The PPC SHA1_Update() function starts off with:
	int SHA1_Update(SHA_CTX *c, const void *ptr, unsigned long n)
	{
	...
		c->len += n << 3;
which will obviously overflow if "n" is bigger than 29 bits, ie 512MB.

So doing the length in bits (or whatever that "<<3" is there for) doesn't seem to be such a great idea.

I guess we could make the caller just always chunk it up, but wouldn't it be nice to fix the PPC SHA1 implementation instead?

That said, the _only_ thing this will ever trigger on in practice is exactly this one case: a large packfile whose checksum was _correctly_ generated - because pack-file generation does it in IO chunks using the csum-file interfaces - but that will be incorrectly checked because we check it all at once.

So as bugs go, it's a fairly benign one.
			Linus
Previous: Linus TorvaldsNext: Paul Mackerras
Message 64 of 67 in “Figured out how to get Mozilla into git”
  1. Jon SmirlJun 9, 2006
  2. Nicolas PitreJun 9, 2006
  3. Martin LanghoffJun 9, 2006
  4. Jon SmirlJun 9, 2006
  5. Jakub NarebskiJun 9, 2006
  6. Linus TorvaldsJun 9, 2006
  7. Nicolas PitreJun 9, 2006
  8. Linus TorvaldsJun 9, 2006
  9. Nicolas PitreJun 9, 2006
  10. Linus TorvaldsJun 9, 2006
  11. Jakub NarebskiJun 9, 2006
  12. Jon SmirlJun 9, 2006
  13. Linus TorvaldsJun 9, 2006
  14. Jon SmirlJun 9, 2006
  15. Linus TorvaldsJun 9, 2006
  16. Jon SmirlJun 9, 2006
  17. Linus TorvaldsJun 9, 2006
  18. Linus TorvaldsJun 9, 2006
  19. Greg KHJun 9, 2006
  20. Martin LanghoffJun 9, 2006
  21. Linus TorvaldsJun 9, 2006
  22. Jon SmirlJun 10, 2006
  23. Linus TorvaldsJun 10, 2006
  24. Jon SmirlJun 10, 2006
  25. Jon SmirlJun 10, 2006
  26. Jakub NarebskiJun 9, 2006
  27. Nicolas PitreJun 9, 2006
  28. Jon SmirlJun 9, 2006
  29. Martin LanghoffJun 10, 2006
  30. Martin LanghoffJun 10, 2006
  31. Linus TorvaldsJun 10, 2006
  32. Linus TorvaldsJun 10, 2006
  33. Jon SmirlJun 10, 2006
  34. Linus TorvaldsJun 10, 2006
  35. Jon SmirlJun 10, 2006
  36. Carl WorthJun 10, 2006
  37. Linus TorvaldsJun 10, 2006
  38. Jakub NarebskiJun 10, 2006
  39. Junio C HamanoJun 10, 2006
  40. Rogan DawesJun 10, 2006
  41. Junio C HamanoJun 10, 2006
  42. Rogan DawesJun 10, 2006
  43. Jakub NarebskiJun 10, 2006
  44. Nicolas PitreJun 10, 2006
  45. Linus TorvaldsJun 10, 2006
  46. Jon SmirlJun 10, 2006
  47. Rogan DawesJun 10, 2006
  48. Linus TorvaldsJun 10, 2006
  49. Jon SmirlJun 10, 2006
  50. Martin LanghoffJun 10, 2006
  51. Junio C HamanoJun 10, 2006
  52. Linus TorvaldsJun 10, 2006
  53. Linus TorvaldsJun 10, 2006
  54. Jon SmirlJun 10, 2006
  55. Junio C HamanoJun 10, 2006
  56. Jon SmirlJun 10, 2006
  57. Timo HirvonenJun 10, 2006
  58. Petr BaudisJun 10, 2006
  59. Lars JohannsenJun 10, 2006
  60. Nicolas PitreJun 11, 2006
  61. Linus TorvaldsJun 18, 2006
  62. Martin LanghoffJun 18, 2006
  63. Linus TorvaldsJun 18, 2006
  64. Broken PPC sha1.. (Re: Figured out how to get Mozilla into git)Linus Torvalds, Jun 18, 2006
  65. Fix PPC SHA1 routine for large input buffersPaul Mackerras, Jun 18, 2006
  66. Linus TorvaldsJun 19, 2006
  67. Pavel RoskinJun 9, 2006

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.