public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Jake Roggenbuck <jakeroggenbuck2@gmail.com>
To: roggenbuckjake@gmail.com
Cc: git@vger.kernel.org, Jake Roggenbuck <jakeroggenbuck2@gmail.com>
Subject: [PATCH 1/1] Exit on invalid diff status of diff_filepair
Date: Tue,  7 Jan 2025 22:01:51 -0800	[thread overview]
Message-ID: <20250108060151.7218-2-jakeroggenbuck2@gmail.com> (raw)
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


  reply	other threads:[~2025-01-08  6:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-19  3:02 bug: Segfault with git diff jake roggenbuck
2025-01-08  6:01 ` [PATCH 0/1] Exit on invalid diff status of diff_filepair Jake Roggenbuck
2025-01-08  6:01   ` Jake Roggenbuck [this message]
2025-04-30 18:50     ` [PATCH 1/1] " Jake Roggenbuck
2025-04-30 18:50       ` Jake Roggenbuck
2025-05-01  6:16       ` Eric Sunshine
2025-05-01 13:23         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250108060151.7218-2-jakeroggenbuck2@gmail.com \
    --to=jakeroggenbuck2@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=roggenbuckjake@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox