Skip to content

Commit e2187fe

Browse files
committed
Merge branch 'rs/fsck-nul-header'
Fsck did not correctly detect a NUL-truncated header in a tag. * rs/fsck-nul-header: fsck: treat a NUL in a tag header as an error t1450: add tests for NUL in headers of commits and tags
2 parents fa7095e + 8a272f2 commit e2187fe

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

fsck.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
711711
}
712712
}
713713

714-
if (verify_headers(buffer, size, &tag->object, options))
714+
ret = verify_headers(buffer, size, &tag->object, options);
715+
if (ret)
715716
goto done;
716717

717718
if (!skip_prefix(buffer, "object ", &buffer)) {

t/t1450-fsck.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ test_expect_success 'integer overflow in timestamps is reported' '
176176
grep "error in commit $new.*integer overflow" out
177177
'
178178

179+
test_expect_success 'commit with NUL in header' '
180+
git cat-file commit HEAD >basis &&
181+
sed "s/author ./author Q/" <basis | q_to_nul >commit-NUL-header &&
182+
new=$(git hash-object -t commit -w --stdin <commit-NUL-header) &&
183+
test_when_finished "remove_object $new" &&
184+
git update-ref refs/heads/bogus "$new" &&
185+
test_when_finished "git update-ref -d refs/heads/bogus" &&
186+
test_must_fail git fsck 2>out &&
187+
cat out &&
188+
grep "error in commit $new.*unterminated header: NUL at offset" out
189+
'
190+
179191
test_expect_success 'malformatted tree object' '
180192
test_when_finished "git update-ref -d refs/tags/wrong" &&
181193
test_when_finished "remove_object \$T" &&
@@ -276,6 +288,26 @@ test_expect_success 'tag with bad tagger' '
276288
grep "error in tag .*: invalid author/committer" out
277289
'
278290

291+
test_expect_success 'tag with NUL in header' '
292+
sha=$(git rev-parse HEAD) &&
293+
q_to_nul >tag-NUL-header <<-EOF &&
294+
object $sha
295+
type commit
296+
tag contains-Q-in-header
297+
tagger T A Gger <[email protected]> 1234567890 -0000
298+
299+
This is an invalid tag.
300+
EOF
301+
302+
tag=$(git hash-object --literally -t tag -w --stdin <tag-NUL-header) &&
303+
test_when_finished "remove_object $tag" &&
304+
echo $tag >.git/refs/tags/wrong &&
305+
test_when_finished "git update-ref -d refs/tags/wrong" &&
306+
test_must_fail git fsck --tags 2>out &&
307+
cat out &&
308+
grep "error in tag $tag.*unterminated header: NUL at offset" out
309+
'
310+
279311
test_expect_success 'cleaned up' '
280312
git fsck >actual 2>&1 &&
281313
test_cmp empty actual

0 commit comments

Comments
 (0)