Skip to content

Commit c50c431

Browse files
npitregitster
authored andcommitted
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 <[email protected]> Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e923eae commit c50c431

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

diff.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,10 +2124,14 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
21242124
}
21252125
else {
21262126
enum object_type type;
2127-
if (size_only)
2127+
if (size_only) {
21282128
type = sha1_object_info(s->sha1, &s->size);
2129-
else {
2129+
if (type < 0)
2130+
die("unable to read %s", sha1_to_hex(s->sha1));
2131+
} else {
21302132
s->data = read_sha1_file(s->sha1, &type, &s->size);
2133+
if (!s->data)
2134+
die("unable to read %s", sha1_to_hex(s->sha1));
21312135
s->should_free = 1;
21322136
}
21332137
}

0 commit comments

Comments
 (0)