{"thread":{"id":"25514","subject":"[PATCH] diff: don't presume empty file when corresponding object is missing","startedAt":"2010-10-22T04:02:27Z","lastAt":"2010-10-22T07:04:46Z","messageCount":2,"participants":["Nicolas Pitre","Uwe Kleine-König"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"154092","messageId":"alpine.LFD.2.00.1010212353550.2764@xanadu.home","threadId":"25514","inReplyTo":null,"subject":"[PATCH] diff: don't presume empty file when corresponding object is missing","fromName":"Nicolas Pitre","fromEmail":"nico@fluxnic.net","sentAt":"2010-10-22T04:02:27Z","receivedAt":"2010-10-22T04:02:27Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"The low-level diff code will happily produce totally bogus diff output \nwith a broken repository via format-patch and friends by treating missing\nobjects as empty files.  Let's prevent that from happening any longer.\n\nReported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>\nSigned-off-by: Nicolas Pitre <nico@fluxnic.net>\n---\n\ndiff --git a/diff.c b/diff.c\nindex 4732b32..b2839f9 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2386,10 +2386,14 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)\n \t}\n \telse {\n \t\tenum object_type type;\n-\t\tif (size_only)\n+\t\tif (size_only) {\n \t\t\ttype = sha1_object_info(s->sha1, &s->size);\n-\t\telse {\n+\t\t\tif (type < 0)\n+\t\t\t\tdie(\"unable to read %s\", sha1_to_hex(s->sha1));\n+\t\t} else {\n \t\t\ts->data = read_sha1_file(s->sha1, &type, &s->size);\n+\t\t\tif (!s->data)\n+\t\t\t\tdie(\"unable to read %s\", sha1_to_hex(s->sha1));\n \t\t\ts->should_free = 1;\n \t\t}\n \t}\n"},{"id":"154116","messageId":"20101022070446.GA19834@pengutronix.de","threadId":"25514","inReplyTo":"alpine.LFD.2.00.1010212353550.2764@xanadu.home","subject":"Re: [PATCH] diff: don't presume empty file when corresponding object is missing","fromName":"Uwe Kleine-König","fromEmail":"u.kleine-koenig@pengutronix.de","sentAt":"2010-10-22T07:04:46Z","receivedAt":"2010-10-22T07:04:46Z","isPatch":true,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Hi Nicolas,\n\nOn Fri, Oct 22, 2010 at 12:02:27AM -0400, Nicolas Pitre wrote:\n> The low-level diff code will happily produce totally bogus diff output \n> with a broken repository via format-patch and friends by treating missing\n> objects as empty files.  Let's prevent that from happening any longer.\n> \n> Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>\nGreat, this fixes format-patch to fail in my tree as advertised.\nTested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>\n\n> Signed-off-by: Nicolas Pitre <nico@fluxnic.net>\n\nThanks\nUwe\n\n-- \nPengutronix e.K.                           | Uwe Kleine-König            |\nIndustrial Linux Solutions                 | http://www.pengutronix.de/  |\n"}]}