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

non-cryptographic hash algorithms in git

From
Jeff King <peff@peff.net>
Date
Jul 31, 2019, 21:22 UTC
Message-ID
<20190731212258.GB1207@sigill.intra.peff.net>
In-Reply-To
<xmqq5zniqg36.fsf@gitster-ct.c.googlers.com>
[breaking the thread since we're way off the original topic, and this
 subject might get more interesting attention]
On Wed, Jul 31, 2019 at 10:17:01AM -0700, Junio C Hamano wrote:
Show 12 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > And here it is for reference with the matching change in test-oidmap,
> > and the adjustments necessary for the test scripts (from master, not
> > from my earlier patch). I think I prefer the simpler "just sort it all"
> > version I posted with the commit message.
> 
> Yeah, let's go with that version.
> 
> I am wondering if we should follow suit to certain language's hash
> implementation to make sure the iteration order is unpredictable to
> catch bad scripts ;-)  Perhaps that is not worth it, either.

That would be a nice side effect, but the real benefit is that it makes hash-collision denial-of-service attacks harder. I experimented with this some when I looked at swapping out the xdiff hash algorithm[1] for murmur, siphash, or similar, but I could never get the performance quite on par with what we have now.

I haven't pursued randomization that much because git's diff engine is a ready-made DoS machine in the first place. If you're diffing untrusted input, you have to be ready to cut it off after using too much CPU and say "nope, this one is too big". That may be less true for our general purpose hashmap, though.

-Peff
[1] I didn't dig up the emails, but this was several years ago, when we
    realized that XDL_FAST_HASH didn't actually work well. I recently
    found out about xxhash:
      https://cyan4973.github.io/xxHash/
    which looks promising. But I haven't gotten around to plugging it in
    and timing the result. Anybody else is welcome to beat me to it. :)
    IIRC, one really tricky thing about our diff code is that it finds
    the newline for each line while it's hashing. That makes it hard to
    plug in an existing hash implementation without going over each line
    twice, and many of them perform poorly if you hand them a byte at a
    time.
Previous: Junio C HamanoNext: René Scharfe
Message 19 of 24 in “RE: [ANNOUNCE] Git v2.23.0-rc0 - Initial test failures on NonStop”
  1. Randall S. BeckerJul 30, 2019
  2. Junio C HamanoJul 30, 2019
  3. Matheus Tavares BernardinoJul 30, 2019
  4. Randall S. BeckerJul 30, 2019
  5. Junio C HamanoJul 30, 2019
  6. Jeff KingJul 30, 2019
  7. Randall S. BeckerJul 30, 2019
  8. Todd ZullingerJul 30, 2019
  9. Jeff KingJul 30, 2019
  10. Junio C HamanoJul 30, 2019
  11. SZEDER GáborJul 30, 2019
  12. Jeff KingJul 31, 2019
  13. Jeff KingJul 31, 2019
  14. Jeff KingJul 31, 2019
  15. Todd ZullingerJul 31, 2019
  16. Jeff KingJul 31, 2019
  17. Jeff KingJul 31, 2019
  18. Junio C HamanoJul 31, 2019
  19. non-cryptographic hash algorithms in gitJeff King, Jul 31, 2019
  20. René ScharfeJul 31, 2019
  21. Jeff KingJul 31, 2019
  22. Todd ZullingerJul 31, 2019
  23. Junio C HamanoJul 31, 2019
  24. Randall S. BeckerJul 30, 2019

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.