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

From: Jake Roggenbuck <[email-masked]>
Date: Tue, 7 Jan 2025 22:01:51 -0800

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 <[email-masked]>
---
 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