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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 13, 2019 at 11:08:01AM +0100, Ævar Arnfjörð Bjarmason wrote:

> > 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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux