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

Re: git fsck does not check the packed-refs file

From
Jeff King <peff@peff.net>
Date
Jan 20, 2024, 01:00 UTC
Message-ID
<20240120010055.GC117170@coredump.intra.peff.net>
In-Reply-To
<ZakIPEytlxHGCB9Y@tanuki>
On Thu, Jan 18, 2024 at 12:15:08PM +0100, Patrick Steinhardt wrote:
Show 10 quoted lines
> > I am guessing that "git fsck" does not check file packed-refs at all.
> > I mean, it does not even attempt to parse it, in order to check
> > whether at least the format makes any sense. Only "git push" does it.
> 
> Indeed it doesn't. While the issue is comparatively easy to spot by
> manually inspecting the `packed-refs` file, I agree that it would be
> great if git-fsck(1) knew how to check the refdb for consistency. This
> problem is only going to get worse once the upcoming reftable backend
> lands -- it is a binary format, and just opening it with a text editor
> to check whether it looks sane-ish stops being a viable option here.

We don't check the packed-refs file explicitly, but we do open and parse it to iterate over the refs it contains. E.g.:

  $ git init
  $ echo foo >.git/packed-refs
  $ git fsck
  Checking object directories: 100% (256/256), done.
  fatal: unexpected line in .git/packed-refs: foo

It's quite possible that the reading code could be more careful. I'd have to see the exact corruption that "git fsck" didn't complain about to say more. If there's a page full of NUL bytes at the end of the file, I wouldn't be surprised if the reading code gently ignores that, which obviously is not ideal.

Fundamentally we cannot catch all cases here; a simple truncation, for example, might yield a valid file that is simply missing some entries. Unlike objects (which make promises about reachability and so on), there is no real "consistency" for the state of the refs. But probably warning if saw a bunch of garbage in the file is a good thing.

I also agree that a specific refdb consistency check would be valuable. There are some things that the regular reading code will not check, but which an fsck should (e.g., if the packed-refs file claims to have the "sorted" trait, we should confirm that).

-Peff
Previous: Patrick Steinhardt
Message 3 of 3 in “git fsck does not check the packed-refs file”
  1. R. DiezJan 18, 2024
  2. Patrick SteinhardtJan 18, 2024
  3. Jeff KingJan 20, 2024

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.