summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorNicolas Pitre <nico@fluxnic.net>2010-10-22 00:02:27 -0400
committerJunio C Hamano <gitster@pobox.com>2010-10-21 22:23:34 -0700
commitc50c4316e1eed362bee387e4cbfbe1138957f75b (patch)
treee35756783e663a7e51bdf6599372df4284e08056 /diff.c
parente923eaeb901ff056421b9007adcbbce271caa7b6 (diff)
downloadgit-c50c4316e1eed362bee387e4cbfbe1138957f75b.tar.gz
diff: don't presume empty file when corresponding object is missing
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/diff.c b/diff.c
index 381cc8d4fd..69cdae54b2 100644
--- a/diff.c
+++ b/diff.c
@@ -2124,10 +2124,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;
}
}