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

[PATCH] diff: don't presume empty file when corresponding object is missing

From
Nicolas Pitre <nico@fluxnic.net>
Date
Oct 22, 2010, 04:02 UTC
Message-ID
<alpine.LFD.2.00.1010212353550.2764@xanadu.home>

The low-level diff code will happily produce totally bogus diff output with a broken repository via format-patch and friends by treating missing objects as empty files. Let's prevent that from happening any longer.

Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
---
diff --git a/diff.c b/diff.c
index 4732b32..b2839f9 100644
--- a/diff.c
+++ b/diff.c
@@ -2386,10 +2386,14 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
 	}
 	else {
 		enum object_type type;
-		if (size_only)
+		if (size_only) {
 			type = sha1_object_info(s->sha1, &s->size);
-		else {
+			if (type < 0)
+				die("unable to read %s", sha1_to_hex(s->sha1));
+		} else {
 			s->data = read_sha1_file(s->sha1, &type, &s->size);
+			if (!s->data)
+				die("unable to read %s", sha1_to_hex(s->sha1));
 			s->should_free = 1;
 		}
 	}
Next: Uwe Kleine-König
Message 1 of 2 in “diff: don't presume empty file when corresponding object is missing”
  1. diff: don't presume empty file when corresponding object is missingNicolas Pitre, Oct 22, 2010
  2. Uwe Kleine-KönigOct 22, 2010

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.