{"thread":{"id":"26313","subject":"[PATCH] Correctly report corrupted objects","startedAt":"2011-01-20T20:12:20Z","lastAt":"2011-01-20T21:17:33Z","messageCount":3,"participants":["Björn Steinbrink","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"159708","messageId":"20110120201220.GD12418@atjola.homenet","threadId":"26313","inReplyTo":null,"subject":"[PATCH] Correctly report corrupted objects","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2011-01-20T20:12:20Z","receivedAt":"2011-01-20T20:12:20Z","isPatch":true,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"The errno check added in commit 3ba7a06 \"A loose object is not corrupt\nif it cannot be read due to EMFILE\" only checked for whether errno is\nnot ENOENT and thus incorrectly treated \"no error\" as an error\ncondition.\n\nBecause of that, it never reached the code path that would report that\nthe object is corrupted and instead caused funny errors like:\n\n  fatal: failed to read object 333c4768ce595793fdab1ef3a036413e2a883853: Success\n\nSo we have to extend the check to cover the case in which the object\nfile was successfully read, but its contents are corrupted.\n\nReported-by: Will Palmer <wmpalmer@gmail.com>\nSigned-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\n---\n sha1_file.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 1cafdfa..d86a8db 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2141,7 +2141,7 @@ void *read_sha1_file_repl(const unsigned char *sha1,\n \t\treturn data;\n \t}\n \n-\tif (errno != ENOENT)\n+\tif (errno && errno != ENOENT)\n \t\tdie_errno(\"failed to read object %s\", sha1_to_hex(sha1));\n \n \t/* die if we replaced an object with one that does not exist */\n-- \n1.7.4.rc2.18.gb20e9\n"},{"id":"159714","messageId":"7vsjwnqoao.fsf@alter.siamese.dyndns.org","threadId":"26313","inReplyTo":"20110120201220.GD12418@atjola.homenet","subject":"Re: [PATCH] Correctly report corrupted objects","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-01-20T21:05:03Z","receivedAt":"2011-01-20T21:05:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Björn Steinbrink <B.Steinbrink@gmx.de> writes:\n\n> The errno check added in commit 3ba7a06 \"A loose object is not corrupt\n> if it cannot be read due to EMFILE\" only checked for whether errno is\n> not ENOENT and thus incorrectly treated \"no error\" as an error\n> condition.\n>\n> Because of that, it never reached the code path that would report that\n> the object is corrupted and instead caused funny errors like:\n>\n>   fatal: failed to read object 333c4768ce595793fdab1ef3a036413e2a883853: Success\n>\n> So we have to extend the check to cover the case in which the object\n> file was successfully read, but its contents are corrupted.\n\nHmm, what is the exact code path that read_object() callchain fails to set\nerrno when it returns a NULL?  It is unclear from the above description.\nIs there a funny object replacement involved?\n\n> Reported-by: Will Palmer <wmpalmer@gmail.com>\n> Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\n> ---\n>  sha1_file.c |    2 +-\n>  1 files changed, 1 insertions(+), 1 deletions(-)\n>\n> diff --git a/sha1_file.c b/sha1_file.c\n> index 1cafdfa..d86a8db 100644\n> --- a/sha1_file.c\n> +++ b/sha1_file.c\n> @@ -2141,7 +2141,7 @@ void *read_sha1_file_repl(const unsigned char *sha1,\n>  \t\treturn data;\n>  \t}\n>  \n> -\tif (errno != ENOENT)\n> +\tif (errno && errno != ENOENT)\n>  \t\tdie_errno(\"failed to read object %s\", sha1_to_hex(sha1));\n>  \n>  \t/* die if we replaced an object with one that does not exist */\n> -- \n> 1.7.4.rc2.18.gb20e9\n"},{"id":"159715","messageId":"7voc7bqnpu.fsf@alter.siamese.dyndns.org","threadId":"26313","inReplyTo":"7vsjwnqoao.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Correctly report corrupted objects","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-01-20T21:17:33Z","receivedAt":"2011-01-20T21:17:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Björn Steinbrink <B.Steinbrink@gmx.de> writes:\n>\n>> The errno check added in commit 3ba7a06 \"A loose object is not corrupt\n>> if it cannot be read due to EMFILE\" only checked for whether errno is\n>> not ENOENT and thus incorrectly treated \"no error\" as an error\n>> condition.\n>>\n>> Because of that, it never reached the code path that would report that\n>> the object is corrupted and instead caused funny errors like:\n>>\n>>   fatal: failed to read object 333c4768ce595793fdab1ef3a036413e2a883853: Success\n>>\n>> So we have to extend the check to cover the case in which the object\n>> file was successfully read, but its contents are corrupted.\n>\n> Hmm, what is the exact code path that read_object() callchain fails to set\n> errno when it returns a NULL?  It is unclear from the above description.\n\nAh, nevermind.  I wasn't thinking.  If for example unpack_sha1_header()\nsays the type bits are garbled, it will return -1 without having any\nsystem calls failed up to that point (because the file itself was mmapped\nand read correctly) and the calling unpack_sha1_file() will return NULL.\n"}]}