From: Matthieu Moy Date: Mon, 6 Feb 2012 16:24:52 +0000 (+0100) Subject: fsck: give accurate error message on empty loose object files X-Git-Tag: v1.7.9.2~26^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=33e42de0d21a8365496e904235bd32fd4659300d;p=git.git fsck: give accurate error message on empty loose object files Since 3ba7a065527a (A loose object is not corrupt if it cannot be read due to EMFILE), "git fsck" on a repository with an empty loose object file complains with the error message fatal: failed to read object : Invalid argument This comes from a failure of mmap on this empty file, which sets errno to EINVAL. Instead of calling xmmap on empty file, we display a clean error message ourselves, and return a NULL pointer. The new message is error: object file .git/objects/09/ is empty fatal: loose object (stored in .git/objects/09/) is corrupt The second line was already there before the regression in 3ba7a065527a, and the first is an additional message, that should help diagnosing the problem for the user. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- diff --git a/sha1_file.c b/sha1_file.c index 25f696529..797b0634c 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1070,6 +1070,11 @@ static void *map_sha1_file(const unsigned char *sha1, unsigned long *size) if (!fstat(fd, &st)) { *size = xsize_t(st.st_size); + if (!*size) { + /* mmap() is forbidden on empty files */ + error("object file %s is empty", sha1_file_name(sha1)); + return NULL; + } map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0); } close(fd);