Skip to content

Git LFS doesn't properly handle zero-sized file #3863

Closed

Description

@slonopotamus

We accidentally got a zero-sized LFS file commited to our repository:

version https://git-lfs.github.com/spec/v1
oid sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
size 0

Please, don't ask how we achieved it. File was properly uploaded to LFS server (also, with zero size). According to LFS spec, file size is required to be "at least zero" so I believe that our custom LFS server is behaving properly by accepting such file.

But now, attempts to download this file into working copy go crazy:

$ git status skyway_panel_single_yellow_s.dds 
On branch dev
Your branch is behind 'origin/dev' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    skyway_panel_single_yellow_s.dds

no changes added to commit (use "git add" and/or "git commit -a")

$ GIT_TRACE=1 git reset --hard e9af3e7ab7055fbd2bc5d09d80356d92034747dc                               
17:20:06.091252 git.c:440               trace: built-in: git reset --hard e9af3e7ab7055fbd2bc5d09d80356d92034747dc
17:20:06.328220 run-command.c:663       trace: run_command: 'git-lfs filter-process'
17:20:06.332127 trace git-lfs: exec: git 'version'
17:20:06.333926 trace git-lfs: exec: git 'config' '-l'
17:20:06.334832 trace git-lfs: Install hook: pre-push, force=false, path=/home/marat/wfgo/.git/hooks/pre-push, upgrading...
17:20:06.334961 trace git-lfs: Install hook: post-checkout, force=false, path=/home/marat/wfgo/.git/hooks/post-checkout, upgrading...
17:20:06.335022 trace git-lfs: Install hook: post-commit, force=false, path=/home/marat/wfgo/.git/hooks/post-commit, upgrading...
17:20:06.335091 trace git-lfs: Install hook: post-merge, force=false, path=/home/marat/wfgo/.git/hooks/post-merge, upgrading...
17:20:06.335161 trace git-lfs: Initialize filter-process
17:20:06.335275 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' 'HEAD' '--symbolic-full-name' 'HEAD'
17:20:06.336289 trace git-lfs: tq: running as batched queue, batch size of 100
17:20:06.336421 trace git-lfs: filepathfilter: accepting "skyway_panel_single_yellow_s.dds"
17:20:06.336974 trace git-lfs: tq: sending batch of size 1
17:20:06.337132 trace git-lfs: run_command: ssh -- [email protected] git-lfs-authenticate wfgo/main.git download
17:20:06.713449 trace git-lfs: api: batch 1 files
17:20:06.713708 trace git-lfs: HTTP: POST https://w1-git.mail.msk/wfgo/main.git/info/lfs/objects/batch
17:20:06.752037 trace git-lfs: HTTP: 200
17:20:06.752074 trace git-lfs: HTTP: {
  "objects" : [ {
    "oid" : "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
    "size" : 0,
    "actions" : {
      "download" : {
        "href" : "https://w1-git.mail.msk:443/wfgo/main.git/info/lfs/storage/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
        "header" : {
          "Authorization" : "Bearer <redacted>"
        }
      }
    }
  } ]
}
17:20:06.752248 trace git-lfs: tq: starting transfer adapter "basic"
17:20:06.752579 trace git-lfs: HTTP: GET https://w1-git.mail.msk:443/wfgo/main.git/info/lfs/storage/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
17:20:06.757092 trace git-lfs: HTTP: 200
HEAD is now at e9af3e7ab7 WFGO-1146: WF19-150 [ptb_D17_up]: Переэкспорт объектов. Итерация_2 Добавлены новые объекты.
17:20:06.920621 run-command.c:46        trace: run_command: running exit handler for pid 24781
17:20:06.920690 trace git-lfs: filepathfilter: rewrite ".git" as "**/.git/**"
17:20:06.920706 trace git-lfs: filepathfilter: rewrite "**/.git" as "**/.git"
17:20:06.920783 trace git-lfs: filepathfilter: accepting "tmp"

$ git status skyway_panel_single_yellow_s.dds 
On branch dev
Your branch is behind 'origin/dev' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   skyway_panel_single_yellow_s.dds

no changes added to commit (use "git add" and/or "git commit -a")

$ file skyway_panel_single_yellow_s.dds 
skyway_panel_single_yellow_s.dds: empty

$ GIT_TRACE=1 git reset --hard e9af3e7ab7055fbd2bc5d09d80356d92034747dc
17:20:20.508361 git.c:440               trace: built-in: git reset --hard e9af3e7ab7055fbd2bc5d09d80356d92034747dc
17:20:20.742889 run-command.c:663       trace: run_command: 'git-lfs filter-process'
17:20:20.746917 trace git-lfs: exec: git 'version'
17:20:20.748711 trace git-lfs: exec: git 'config' '-l'
17:20:20.749643 trace git-lfs: Install hook: pre-push, force=false, path=/home/marat/wfgo/.git/hooks/pre-push, upgrading...
17:20:20.749792 trace git-lfs: Install hook: post-checkout, force=false, path=/home/marat/wfgo/.git/hooks/post-checkout, upgrading...
17:20:20.749853 trace git-lfs: Install hook: post-commit, force=false, path=/home/marat/wfgo/.git/hooks/post-commit, upgrading...
17:20:20.749895 trace git-lfs: Install hook: post-merge, force=false, path=/home/marat/wfgo/.git/hooks/post-merge, upgrading...
17:20:20.749945 trace git-lfs: Initialize filter-process
17:20:20.750012 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' 'HEAD' '--symbolic-full-name' 'HEAD'
17:20:20.751132 trace git-lfs: tq: running as batched queue, batch size of 100
17:20:20.751216 trace git-lfs: filepathfilter: accepting "skyway_panel_single_yellow_s.dds"
17:20:20.751262 trace git-lfs: Removing /storage/lfs/objects/e3/b0/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, size 0 is invalid
fatal: skyway_panel_single_yellow_s.dds: smudge filter lfs failed
17:20:20.751343 run-command.c:46        trace: run_command: running exit handler for pid 24858
17:20:20.751417 trace git-lfs: filepathfilter: rewrite ".git" as "**/.git/**"
17:20:20.751440 trace git-lfs: filepathfilter: rewrite "**/.git" as "**/.git"
17:20:20.751474 trace git-lfs: filepathfilter: accepting "tmp"

$ git status skyway_panel_single_yellow_s.dds 
On branch dev
Your branch is behind 'origin/dev' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    skyway_panel_single_yellow_s.dds

no changes added to commit (use "git add" and/or "git commit -a")

And it continues to switch between these two states infinitely.

Activity

  1. slonopotamus commented on Oct 16, 2019

    @slonopotamus
    ContributorAuthor

    While spec says that An empty file is the pointer for an empty file. That is, empty files are passed through LFS without any change., it doesn't restrict uploading of empty files to LFS server, this statement doesn't seem to enforce anything since server is required to accept zero-sized upload requests.

    Also, see #2447.

  2. mathstuf commented on Oct 16, 2019

    @mathstuf
    Contributor

    The statement was added to document the behavior of git-lfs itself with respect to the files. That the server did not handle this well was not taken into consideration at the time because I couldn't get a 0-byte file to be turned into an LFS pointer in the first place. I suspect that this is just a bug and if it also ends up resulting in a comment in the spec about server-side expectations for empty files, that sounds OK to me.

  3. slonopotamus commented on Oct 16, 2019

    @slonopotamus
    ContributorAuthor

    Anyway, #3864 at least stops Git-LFS from oscillating between two states. Overall, I'd prefer zero-sized file was not a special case at all. Because why?

  4. mathstuf commented on Oct 16, 2019

    @mathstuf
    Contributor

    I agree with that. You'd have to ask a developer why it was such a special case on the git side. Was it a corner case in git smudge and git clean that is now fixed? If so, what version of git fixed it?

  5. slonopotamus commented on Oct 16, 2019

    @slonopotamus
    ContributorAuthor

    I believe nothing has changed since discussion in #2447. LFS server spec allows empty file upload, but vanilla Git-LFS just doesn't use this option. We used different client to upload problematic file into LFS server. And while this upload didn't violate LFS server spec, it triggered troubles in Git-LFS client implementation because it special-cases empty file. Note that this upload was not intentional.

  6. bk2204 commented on Oct 17, 2019

    @bk2204
    Member

    I think, having documented that the LFS pointer for an empty file is empty, it's probably better for us to keep doing this. Otherwise, we end up with situations where round-tripping becomes problematic, since there are two possible serializations of the same file.

    I've opened an issue to track improving our parsing as #3865.

  7. slonopotamus commented on Oct 17, 2019

    @slonopotamus
    ContributorAuthor

    I think I'll close this issue. With #3864 merged, Git-LFS accepts both variants of empty file but writes "canonical" form - direct empty file, without LFS pointer.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions