Skip to content

Commit 33e42de

Browse files
moygitster
authored andcommitted
fsck: give accurate error message on empty loose object files
Since 3ba7a06 (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 <sha1>: 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/<rest-of-sha1> is empty fatal: loose object <sha1> (stored in .git/objects/09/<rest-of-sha1>) is corrupt The second line was already there before the regression in 3ba7a06, and the first is an additional message, that should help diagnosing the problem for the user. Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3ba7a06 commit 33e42de

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

sha1_file.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,11 @@ static void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
10701070

10711071
if (!fstat(fd, &st)) {
10721072
*size = xsize_t(st.st_size);
1073+
if (!*size) {
1074+
/* mmap() is forbidden on empty files */
1075+
error("object file %s is empty", sha1_file_name(sha1));
1076+
return NULL;
1077+
}
10731078
map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0);
10741079
}
10751080
close(fd);

0 commit comments

Comments
 (0)