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

Re: [RFC PATCH] pack-refs: fail on falsely sorted packed-refs

From
Jeff King <peff@peff.net>
Date
Feb 14, 2019, 06:06 UTC
Message-ID
<20190214060657.GA20997@sigill.intra.peff.net>
In-Reply-To
<87lg2kj91a.fsf@evledraar.gmail.com>
On Wed, Feb 13, 2019 at 11:08:01AM +0100, Ævar Arnfjörð Bjarmason wrote:
Show 21 quoted lines
> > I happened to have a not really sorted packed-refs file. As you might guess,
> > it was quite wtf-ing experience. It worked, mostly, but there was one branch
> > which just did not resolve, regardless of existing and being presented in
> > for-each-refs output.
> >
> > I don't know where the corruption came from. I should admit it could even be a manual
> > editing but last time I did it (in that reporitory) was several years ago so it is unlikely.
> >
> > I am not sure what should be the proper fix. I did a minimal detection, so that
> > it does not go unnoticed. Probably next step would be either fixing in `git fsck` call.
> >
> >  refs/packed-backend.c               | 15 +++++++++++++++
> >  t/t3212-pack-refs-broken-sorting.sh | 26 ++++++++++++++++++++++++++
> >  2 files changed, 41 insertions(+)
> >  create mode 100755 t/t3212-pack-refs-broken-sorting.sh
> 
> This is not an area I'm very familiar with. So mostly commeting on
> cosmetic issues with the patch. FWIW the "years back" issue you had
> could be that an issue didn't manifest until now, i.e. in a sorted file
> format you can get lucky and not see corruption for a while with a
> random insert.

It actually shouldn't be that old a breakage. Until 02b920f3f7 (read_packed_refs(): ensure that references are ordered when read, 2017-09-25), we did not assume the file was sorted (even though we always wrote it out sorted). And we continue to not assume the file is sorted unless it is written out with an explicit "sorted" trait in the header (which we started doing in that commit, too).

So a years-old manual edit would not have the "sorted" trait, and should not have manifested as a problem, even now. Likewise for a years-old bug. It would have to be a bug in a _new_ writer which writes out the sorted trait. If there is such a bug in our implementation, this would be the first report we've seen. Given the number of times pack-refs has been run, without further evidence I'm inclined to think it was some weird manual edit, or maybe an alternate implementation (though one would _hope_ they would not write out the sorted trait without actually sorting!).

I agree with all of the cosmetic issues you mentioned. As far as what the patch itself does, I think it's OK. We could probably go further and actually sort it (or even just write it out without a "sorted" trait, which means the next read would load it all into memory and sort it). That's a little friendlier, since just dying leaves the user to fix it up themselves. But given that we expect this code to trigger approximately never, it's probably not worth spending much time on a fancy solution.

-Peff
Previous: Max KirillovNext: Max Kirillov
Message 10 of 12 in “pack-refs: fail on falsely sorted packed-refs”
  1. pack-refs: fail on falsely sorted packed-refsMax Kirillov, Jan 30, 2019
  2. Eric SunshineJan 30, 2019
  3. Max KirillovJan 31, 2019
  4. pack-refs: fail on falsely sorted packed-refsMax Kirillov, Feb 8, 2019
  5. Eric SunshineFeb 8, 2019
  6. Max KirillovFeb 13, 2019
  7. Ævar Arnfjörð BjarmasonFeb 13, 2019
  8. SZEDER GáborFeb 13, 2019
  9. Max KirillovFeb 23, 2019
  10. Jeff KingFeb 14, 2019
  11. Max KirillovFeb 23, 2019
  12. Max KirillovFeb 13, 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.