Skip to contentSkip to conversation

fsck: fix bogus commit header check

PATCH In review Jonathan Nieder 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsck: fix bogus commit header check

daae1922 (fsck: check ident lines in commit objects, 2010-04-24) taught fsck to expect commit objects to have the form

tree <object name>
<parents>
author <valid ident string>
committer <valid ident string>

log message

The check is overly strict: for example, it errors out with the message “expected blank line” for perfectly valid commits with an "encoding ISO-8859-1" line.

Later it might make sense to teach fsck about the rest of the header and warn about unrecognized header lines, but for simplicity, let’s accept arbitrary trailing lines for now.

---
Patch is against jn/fsck-ident (daae1922).

As you might expect, this triggers for some real-world repos. Many thanks to Tuncer for the catch.

 fsck.c          |    2 --
 t/t1450-fsck.sh |    8 ++++++++
 2 files changed, 8 insertions(+), 2 deletions(-)
fsck.c +0 -2
index ae9ae1a..3d05d4a 100644
@@ -311,8 +311,6 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
 	err = fsck_ident(&buffer, &commit->object, error_func);
 	if (err)
 		return err;
-	if (*buffer != '\n')
-		return error_func(&commit->object, FSCK_ERROR, "invalid format - expected blank line");
 	if (!commit->tree)
 		return error_func(&commit->object, FSCK_ERROR, "could not load commit's tree %s", sha1_to_hex(tree_sha1));
 
t/t1450-fsck.sh +8 -0
index 22a80c8..759cf12 100755
@@ -5,7 +5,9 @@ test_description='git fsck random collection of tests'
 . ./test-lib.sh
 
 test_expect_success setup '
+	git config i18n.commitencoding ISO-8859-1 &&
 	test_commit A fileA one &&
+	git config --unset i18n.commitencoding &&
 	git checkout HEAD^0 &&
 	test_commit B fileB two &&
 	git tag -d A B &&
@@ -28,6 +30,12 @@ test_expect_success 'loose objects borrowed from alternate are not missing' '
 	)
 '
 
+test_expect_success 'valid objects appear valid' '
+	{ git fsck 2>out; true; } &&
+	! grep error out &&
+	! grep fatal out
+'
+
 # Corruption tests follow.  Make sure to remove all traces of the
 # specific corruption you test afterwards, lest a later test trip over
 # it.
Signature · 1 line
1.7.1.232.g3072.dirty
#1 lore raw
Quoted 8 lines · Jonathan Nieder

daae1922 (fsck: check ident lines in commit objects, 2010-04-24) taught fsck to expect commit objects to have the form

tree <object name>
<parents>
author <valid ident string>
committer <valid ident string>

Quoted 6 lines

log message

The check is overly strict: for example, it errors out with the message “expected blank line” for perfectly valid commits with an "encoding ISO-8859-1" line.
...

Thanks.