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

[RFC PATCH 2b] parse_commit: refuse to load commit without \n\n separator

From
Thomas Rast <trast@student.ethz.ch>
Date
Feb 28, 2012, 10:37 UTC
Message-ID
<3f4c4b0656305bec08e87ad56ee3253b010a5a9d.1330425111.git.trast@student.ethz.ch>
In-Reply-To
<010901fbfffe0f806bb19d556ebc1e512a4697f4.1330425111.git.trast@student.ethz.ch>

A commit object consists of a series of headers, terminated by a blank line (\n\n), followed by the message.

Refuse to parse a commit which does not contain this \n\n. This also lets git-fsck detect the breakage.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---

This is the more drastic approach compared to 2a. Since the code in pretty.c was broken given such input, I would favor this. It does, however, remove the possibility of fixing up such a broken commit with the tools git provides (other than resorting to git-hash-object and git-replace).

 commit.c |    3 +++
 1 file changed, 3 insertions(+)
diff --git a/commit.c b/commit.c
index 4b39c19..502675c 100644
--- a/commit.c
+++ b/commit.c
@@ -265,6 +265,9 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
 	if (get_sha1_hex(bufptr + 5, parent) < 0)
 		return error("bad tree pointer in commit %s",
 			     sha1_to_hex(item->object.sha1));
+	if (!memmem(bufptr, size, "\n\n", 2))
+		return error("commit object %s is missing \\n\\n separator",
+			     sha1_to_hex(item->object.sha1));
 	item->tree = lookup_tree(parent);
 	bufptr += 46; /* "tree " + "hex sha1" + "\n" */
 	pptr = &item->parents;
-- 
1.7.9.2.467.g7fee4
Previous: Junio C HamanoNext: Junio C Hamano
Message 12 of 13 in “commit: allow {--amend|-c foo} when {HEAD|foo} has empty message”
  1. commit: allow {--amend|-c foo} when {HEAD|foo} has empty messageThomas Rast, Feb 28, 2012
  2. Jeff KingFeb 28, 2012
  3. Jeff KingFeb 28, 2012
  4. Thomas RastFeb 28, 2012
  5. Junio C HamanoFeb 28, 2012
  6. Jeff KingFeb 28, 2012
  7. Junio C HamanoFeb 28, 2012
  8. commit: allow {--amend|-c foo} when {HEAD|foo} has empty messageThomas Rast, Feb 28, 2012
  9. pretty: detect missing \n\n in commit messageThomas Rast, Feb 28, 2012
  10. Nguyen Thai Ngoc DuyFeb 28, 2012
  11. Junio C HamanoFeb 28, 2012
  12. parse_commit: refuse to load commit without \n\n separatorThomas Rast, Feb 28, 2012
  13. Junio C HamanoFeb 28, 2012

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.