git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Corrupted (?) commit 6e6db85e confusing gitk

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Dec 2, 2007, 21:25 UTC
Message-ID
<alpine.LFD.0.9999.0712021322580.8458@woody.linux-foundation.org>
In-Reply-To
<7vmyssvn55.fsf@gitster.siamese.dyndns.org>
On Sun, 2 Dec 2007, Junio C Hamano wrote:
>
> The next issue would be to find who could pass an empty GIT_AUTHOR_DATE
> without noticing...

In the meantime, here's a not-very-well-tested patch to fsck to at least notice this.

Of course, in the name of containment it would probably be even better if parse_commit() did it, because then people would be unable to pull from such a corrupt repository! But this would seem to be at least a slight step in the right direction.

		Linus
---
 builtin-fsck.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/builtin-fsck.c b/builtin-fsck.c
index e4874f6..309212c 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -351,8 +351,48 @@ static int fsck_tree(struct tree *item)
 	return retval;
 }
 
+static int parse_commit_line(struct commit *commit, const char *expect, const char *buffer)
+{
+	char *end;
+	const char *p;
+	int len = strlen(expect);
+	int saw_lt = 0;
+
+	if (memcmp(buffer, expect, len))
+		goto bad;
+	p = (char *)buffer + len;
+	if (*p != ' ')
+		goto bad;
+	while (*++p != '>') {
+		if (*p == '<')
+			saw_lt++;
+		if (!*p)
+			goto bad;
+	}
+	if (saw_lt != 1)
+		goto bad;
+	if (*++p != ' ')
+		goto bad;
+
+	/* Date in seconds since the epoch (UTC) */
+	if (strtoul(p, &end, 10) == ULONG_MAX)
+		goto bad;
+	if (*end++ != ' ')
+		goto bad;
+
+	/* TZ that date was done in */
+	if (strtoul(end, &end, 10) == ULONG_MAX)
+		goto bad;
+	if (*end++ != '\n')
+		goto bad;
+	return end - buffer;
+bad:
+	return objerror(&commit->object, "invalid format - missing or corrupt '%s'", expect);
+}
+
 static int fsck_commit(struct commit *commit)
 {
+	int len;
 	char *buffer = commit->buffer;
 	unsigned char tree_sha1[20], sha1[20];
 
@@ -370,8 +410,21 @@ static int fsck_commit(struct commit *commit)
 			return objerror(&commit->object, "invalid 'parent' line format - bad sha1");
 		buffer += 48;
 	}
-	if (memcmp(buffer, "author ", 7))
-		return objerror(&commit->object, "invalid format - expected 'author' line");
+
+	/*
+	 * We check the author/committer lines for completeness.
+	 * But errors here aren't fatal to the rest of the parsing.
+	 */
+	len = parse_commit_line(commit, "author", buffer);
+	if (len >= 0) {
+		buffer += len;
+		len = parse_commit_line(commit, "committer", buffer);
+		if (len >= 0) {
+			buffer += len;
+			if (*buffer != '\n')
+				objerror(&commit->object, "invalid format - missing or corrupt end-of-headers");
+		}
+	}
 	free(commit->buffer);
 	commit->buffer = NULL;
 	if (!commit->tree)
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 18 in “Corrupted (?) commit 6e6db85e confusing gitk”
  1. Steffen ProhaskaDec 2, 2007
  2. Wincent ColaiutaDec 2, 2007
  3. gitk: Add workaround to handle corrupted author dateSteffen Prohaska, Dec 2, 2007
  4. Junio C HamanoDec 2, 2007
  5. Brian DowningDec 2, 2007
  6. Linus TorvaldsDec 2, 2007
  7. Junio C HamanoDec 2, 2007
  8. Linus TorvaldsDec 2, 2007
  9. Junio C HamanoDec 2, 2007
  10. Linus TorvaldsDec 2, 2007
  11. Fix --signoff in builtin-commit differently.Junio C Hamano, Dec 2, 2007
  12. Johannes SchindelinDec 2, 2007
  13. Michael GebetsroitherDec 2, 2007
  14. Junio C HamanoDec 2, 2007
  15. Johannes SchindelinDec 2, 2007
  16. Linus TorvaldsDec 2, 2007
  17. Junio C HamanoDec 2, 2007
  18. Junio C HamanoDec 2, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.