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

Re: git bugs

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Jun 10, 2008, 16:58 UTC
Message-ID
<alpine.LNX.1.00.0806101236120.19665@iabervon.org>
In-Reply-To
<832adb090806100141n69c086a2v2f59fe94b2f4ead3@mail.gmail.com>
On Tue, 10 Jun 2008, Ben Lynn wrote:
Show 32 quoted lines
> 2. Kudos to everyone who figured out the nasty race condition and its
> complex solution as described in Documentation/technical/racy-git.txt
> and the comments of read-cache.c. It took me a while to get my head
> around it.
> 
> Unfortunately, the solution isn't perfect. Try this:
> 
> $ echo xyzzy > file
> $ git update-index --add file   # don't zero size since contents match
> $ echo frotz > file             # all stats still match, contents don't
> $ echo nitfol > other  # can be done much earlier
> $ git update-index --add other  # now the cached size is zeroed
> $ : > file                      # zero the file size muahahaha
> $ # Type fast! The above must take place within the same second! ;-)
> $ sleep 2
> $ echo filfre > other
> $ git update-index --add other  # stats of "file" match, hash is wrong
> 
> Essentially, we trigger two index writes that avoid operations on
> "file": one immediately after "file" is first committed and identified
> as racily clean, and the second some time later, after we have
> sneakily zeroed the file behind git's back (after previously editing
> its contents in place). We defeat the safeguards and end up with a bad
> hash in the index that appears valid.
> 
> The"other" file merely causes index writes without reading the "file"
> entry. It is also racily clean in the above, but this is irrelevant.
> 
> It's unlikely this sequence of operations would occur in real usage,
> but I'd sleep better if this index corruption bug were eliminated. One
> practical but unsatisfactory easy "fix" is to mark racily clean
> entries with SIZE_MAX instead of 0.

We could distinguish a "racily clean" entry from a 0-length file entry based on the hash. That is, say that a file isn't clean even though the size matches, if the size is 0 and the entry's hash isn't the same as the file's hash, which is e69de29bb2d1d6434b8b29ae775ad8c2e48c5391. Nice thing about 0-length files is that you can compute their hashes without reading them.

	-Daniel
*This .sig left intentionally blank*
Previous: Ben LynnNext: Linus Torvalds
Message 2 of 35 in “git bugs”
  1. Ben LynnJun 10, 2008
  2. Daniel BarkalowJun 10, 2008
  3. Linus TorvaldsJun 10, 2008
  4. Ben LynnJun 10, 2008
  5. Linus TorvaldsJun 10, 2008
  6. Ben LynnJun 10, 2008
  7. Junio C HamanoJun 10, 2008
  8. Ben LynnJun 11, 2008
  9. Junio C HamanoJun 11, 2008
  10. Ben LynnJun 11, 2008
  11. Ben LynnJun 11, 2008
  12. Stephen R. van den BergJun 11, 2008
  13. Ben LynnJun 12, 2008
  14. Linus TorvaldsJun 11, 2008
  15. Ben LynnJun 11, 2008
  16. Linus TorvaldsJun 11, 2008
  17. Ben LynnJun 11, 2008
  18. Linus TorvaldsJun 11, 2008
  19. Ben LynnJun 11, 2008
  20. Ben LynnJun 11, 2008
  21. Linus TorvaldsJun 11, 2008
  22. Ben LynnJun 11, 2008
  23. Linus TorvaldsJun 11, 2008
  24. Ben LynnJun 11, 2008
  25. Linus TorvaldsJun 11, 2008
  26. Ben LynnJun 11, 2008
  27. Junio C HamanoJun 11, 2008
  28. Linus TorvaldsJun 11, 2008
  29. Junio C HamanoJun 12, 2008
  30. Jeff KingJun 13, 2008
  31. Junio C HamanoJun 13, 2008
  32. Jeff KingJun 14, 2008
  33. Shawn O. PearceJun 12, 2008
  34. Ben LynnJun 12, 2008
  35. Johannes SchindelinJun 12, 2008

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.