@@ -176,6 +176,18 @@ test_expect_success 'integer overflow in timestamps is reported' '
176
176
grep "error in commit $new.*integer overflow" out
177
177
'
178
178
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
+
179
191
test_expect_success ' malformatted tree object' '
180
192
test_when_finished "git update-ref -d refs/tags/wrong" &&
181
193
test_when_finished "remove_object \$T" &&
@@ -276,6 +288,26 @@ test_expect_success 'tag with bad tagger' '
276
288
grep "error in tag .*: invalid author/committer" out
277
289
'
278
290
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
+
279
311
test_expect_success ' cleaned up' '
280
312
git fsck >actual 2>&1 &&
281
313
test_cmp empty actual
0 commit comments