diff mbox series

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

Message ID 20250108060151.7218-2-jakeroggenbuck2@gmail.com (mailing list archive)
State New
Headers show
Series Exit on invalid diff status of diff_filepair | expand

Commit Message

Jake Roggenbuck Jan. 8, 2025, 6:01 a.m. UTC
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 mbox series

Patch

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);
 	}