Skip to content

Commit

Permalink
Block paths which might be misinterpreted as alternate data streams
Browse files Browse the repository at this point in the history
ref #679

Windows disallows the colon `:` character in file names. However many
win32 file APIs allow path specifications of the form `<file path>:<stuff>`
when reading or writing files. These are interpreted as pointing to
the *alternate data stream* named `<stuff>` within the `<file path>` file.

Documentation on alternate data streams:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364404(v=vs.85).aspx

Git for Windows, ignorant of file streams, will incorrectly map a Unix
file named like `foo:bar` into the `bar` alternate stream of a file
`foo`. This results in an unexpected file `foo` with size 0 in the working
tree, and (depending on core.fscache setting), the expected "foo:bar" file
being flagged as deleted (or maybe not).

It would be preferrable if Git for Windows detected such files and issued
errors, similar to how it does for various other invalid path situations.
This would help reduce pain and make things less confusing for those
working in a mixed Unix/Windows team.

This change adds a check for ':' so that we never accidentally unpack a file
into an alternate stream by accident. Any file path with a ':' is considered
invalid, which is perfectly sensible for the purposes of git.

If such a file is indeed detected and blocked, users can instruct git to
totally ignore it via `git update-index --assume-unchanged`, just like
they need to today for other invalid path situations.

NB - a determined Windows user can still confuse the system in certain ways
by explicitly creating alternate streams, but that requires exceptional
user effort and is judged to be not worth pursuing at this time.

Signed-off-by: Lincoln Atkinson <lincoln.atkinson@hotmail.com>
  • Loading branch information
latkin committed Mar 4, 2016
1 parent 47d64e6 commit c4a42f2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,9 +821,10 @@ int verify_path(const char *path)
return 0;
c = *path++;
if ((c == '.' && !verify_dotfile(path)) ||
is_dir_sep(c) || c == '\0')
is_dir_sep(c) || c == ':' || c == '\0')
return 0;
}
} else if (c == ':')
return 0;
c = *path++;
}
}
Expand Down

0 comments on commit c4a42f2

Please sign in to comment.