You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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.
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.
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.
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 :)
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 :) .
Activity
slonopotamus commentedon Oct 17, 2019
I'm not sure this is a good idea. Because it can break existing repos and they will be forced to rewrite history.
bk2204 commentedon Oct 17, 2019
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.
slonopotamus commentedon Oct 17, 2019
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.
mathstuf commentedon Oct 17, 2019
I agree that an escape hatch would at least be necessary if this were to occur. It can't be in
.lfsconfigeither because the old commits likely won't set that either. Same with having to set.git/configsettings 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 0problem 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.rsmathstuf commentedon Oct 17, 2019
Just realized that
oidis likely not found as invalid right now. I'll add a testcase and fix for it this week if it is a problem.bk2204 commentedon Oct 17, 2019
I think what we'll probably do is add a strict mode which fails and make
git lfs pointeruse 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 fsckcheck for this issue in the future.slonopotamus commentedon Oct 17, 2019
The problem with
size 0described 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.
slonopotamus commentedon Oct 17, 2019
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 :)
mathstuf commentedon Oct 17, 2019
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 :) .