@matheusbsbs / matheus-bagliano / commits / c50c4316e1
Fork 0

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>

Nicolas Pitre committed Oct 22, 2010 at 00:02 UTC c50c4316e1eed362bee387e4cbfbe1138957f75b
1 file changed +6 -2
diff.c
+6 -2
@@ -2124,10 +2124,14 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
2124 }
2125 else {
2126 enum object_type type;
2127 - if (size_only)
2127 + if (size_only) {
2128 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 {
2132 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));
2135 s->should_free = 1;
2136 }
2137 }