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

[PATCH 1/1] Exit on invalid diff status of diff_filepair

From
Jake Roggenbuck <jakeroggenbuck2@gmail.com>
Date
Jan 8, 2025, 06:01 UTC
Message-ID
<20250108060151.7218-2-jakeroggenbuck2@gmail.com>
In-Reply-To
<20250108060151.7218-1-jakeroggenbuck2@gmail.com>

Add a check for the invalid status of `0` for `diff_filepair` when certain object files are missing. When these object files are missing, 'git log' returns 'fatal: bad object HEAD' but 'git diff' segfaults.

Normally, the `diff_filepair` status should be a character, but when object files are removed, status becomes a zero character which isn't listed as one of the possible status letters in `Documentation/diff-format.txt`.

This patch checks for that invalid status character and gracefully exits with an error message.

Signed-off-by: Jake Roggenbuck <jakeroggenbuck2@gmail.com>
---
 diff.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/diff.c b/diff.c
index 6c96154fed..aeab1ac445 100644
--- a/diff.c
+++ b/diff.c
@@ -7018,6 +7018,10 @@ void diff_queued_diff_prefetch(void *repository)
 
 	for (i = 0; i < q->nr; i++) {
 		struct diff_filepair *p = q->queue[i];
+
+		if (!p->status)
+			die("invalid diff status");
+
 		diff_add_if_missing(repo, &to_fetch, p->one);
 		diff_add_if_missing(repo, &to_fetch, p->two);
 	}
-- 
2.47.0
Previous: Jake RoggenbuckNext: Jake Roggenbuck
Message 3 of 7 in “bug: Segfault with git diff”
  1. jake roggenbuckMay 19, 2024
  2. 0/1 Exit on invalid diff status of diff_filepairJake Roggenbuck, Jan 8, 2025
  3. 1/1 Exit on invalid diff status of diff_filepairJake Roggenbuck, Jan 8, 2025
  4. Jake RoggenbuckApr 30, 2025
  5. Jake RoggenbuckApr 30, 2025
  6. Eric SunshineMay 1, 2025
  7. Junio C HamanoMay 1, 2025

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.