Skip to content

Harden pointer parsing #3865

Open
Open

Description

@bk2204

Currently, our pointer parsing is a bit too generous. We accept carriage returns as well as files with an explicit size of zero. Neither one of these is conformant with the spec, and accepting them leads to round-tripping problems, since multiple files can represent the same object. This leads to Git showing the file as changed in some cases.

We should reject both of these cases and add tests for handling them (as well as empty files) appropriately.

Activity

  1. slonopotamus commented on Oct 17, 2019

    @slonopotamus
    Contributor

    I'm not sure this is a good idea. Because it can break existing repos and they will be forced to rewrite history.

  2. bk2204 commented on Oct 17, 2019

    @bk2204
    MemberAuthor

    Unfortunately, we already know there are repositories that experience problems with these situations, such as #3787, because round-tripping doesn't work. It's better to have things fail up front than have random breakage and constantly modified files down the line.

  3. slonopotamus commented on Oct 17, 2019

    @slonopotamus
    Contributor

    I'll say it once again: marking files as modified can be easily fixed by just commiting them. This is annoying, it would be better if tools saved files properly in the first place, yes.

    But. If git-lfs rejects contents that is already commited to repository, it cannot be easily fixed. It will require history rewrites, force-pushes and other nasty stuff. It can become even worse if repository owner and user who stumbled on rejected file are different persons.

    Hardening of parsing will mean that any repository that uses Git-LFS might become corrupt because somewhere deep in its history there lies a single LFS pointer that now became illegal. Such problems cannot even be easily detected without writing some scripts that traverse full repo history and validate all LFS pointers they encounter.

    So please, if you plan to reject LFS pointers that were accepted before, think twice before doing that. Or even better, five times.

  4. mathstuf commented on Oct 17, 2019

    @mathstuf
    Contributor

    I agree that an escape hatch would at least be necessary if this were to occur. It can't be in .lfsconfig either because the old commits likely won't set that either. Same with having to set .git/config settings all the time. Adding a new clean/smudge pair doesn't sound reasonable either since everyone would have to move over to having it as well.

    However, for posterity, I'll link to my implementation of a check for commits that enforces LFS pointer validity (it's how I found the size 0 problem in the first place). It follows the spec as closely as possible with warnings for SHOULD and errors for MUST items. There are also test cases for all the error paths available in the history of the repository for anyone interested (commit hashes in the test block at bottom of the file). https://gitlab.kitware.com/utils/rust-git-checks/blob/master/git-checks/src/lfs_pointer.rs

  5. mathstuf commented on Oct 17, 2019

    @mathstuf
    Contributor

    Just realized that oid is likely not found as invalid right now. I'll add a testcase and fix for it this week if it is a problem.

  6. bk2204 commented on Oct 17, 2019

    @bk2204
    MemberAuthor

    I think what we'll probably do is add a strict mode which fails and make git lfs pointer use that and use a lax mode for parsing otherwise. We'll then perform a full switch over to strict at 3.0.

    We can also make git lfs fsck check for this issue in the future.

  7. slonopotamus commented on Oct 17, 2019

    @slonopotamus
    Contributor

    The problem with size 0 described in #3863 was triggered by the fact that LFS server protocol spec explicitly says that server has to accept size if it is "at least zero". If it wasn't the case, we would detect the problem when zero-sized file was attempted to be pushed to repo (and rejected). Even lfs-test-server accepts zero-sized file, if I am reading its code properly.

    So, if git-lfs wanted to declare zero-sized LFS object an invalid thing, it didn't do enough things to prevent this from happening and now it is a bit too late and not worth it from my point of view.

  8. slonopotamus commented on Oct 17, 2019

    @slonopotamus
    Contributor

    BTW, we also had a funny case when we managed to create an LFS object whose contents was in turn an LFS pointer file. Luckily, such crazy thing wasn't pushed anywhere :)

  9. mathstuf commented on Oct 17, 2019

    @mathstuf
    Contributor

    I'd actually be concerned if LFS couldn't store an LFS pointer in itself. That seems to me like LFS is caring too much about the content of the blobs. Though I do grant that it would be mightily confusing :) .

  10. added this to the v3.0.0 milestone on Feb 3, 2021
  11. removed this from the v3.0.0 milestone on Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions