Skip to content

Commit be4d6a3

Browse files
thaliaarchigitster
authored andcommitted
fast-import: forbid escaped NUL in paths
NUL cannot appear in paths. Even disregarding filesystem path limitations, the tree object format delimits with NUL, so such a path cannot be encoded by Git. When a quoted path is unquoted, it could possibly contain NUL from "\000". Forbid it so it isn't truncated. fast-import still has other issues with NUL, but those will be addressed later. Signed-off-by: Thalia Archibald <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a923a04 commit be4d6a3

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

Documentation/git-fast-import.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ and its value must be in canonical form. That is it must not:
661661

662662
The root of the tree can be represented by an empty string as `<path>`.
663663

664+
`<path>` cannot contain NUL, either literally or escaped as `\000`.
664665
It is recommended that `<path>` always be encoded using UTF-8.
665666

666667
`filedelete`

builtin/fast-import.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,8 @@ static void parse_path(struct strbuf *sb, const char *p, const char **endp,
22702270
if (*p == '"') {
22712271
if (unquote_c_style(sb, p, endp))
22722272
die("Invalid %s: %s", field, command_buf.buf);
2273+
if (strlen(sb->buf) != sb->len)
2274+
die("NUL in %s: %s", field, command_buf.buf);
22732275
} else {
22742276
/*
22752277
* Unless we are parsing the last field of a line,

t/t9300-fast-import.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,6 +3300,7 @@ test_path_base_fail () {
33003300
local change="$1" prefix="$2" field="$3" suffix="$4"
33013301
test_path_fail "$change" 'unclosed " in '"$field" "$prefix" '"hello.c' "$suffix" "Invalid $field"
33023302
test_path_fail "$change" "invalid escape in quoted $field" "$prefix" '"hello\xff"' "$suffix" "Invalid $field"
3303+
test_path_fail "$change" "escaped NUL in quoted $field" "$prefix" '"hello\000"' "$suffix" "NUL in $field"
33033304
}
33043305
test_path_eol_quoted_fail () {
33053306
local change="$1" prefix="$2" field="$3"

0 commit comments

Comments
 (0)