Code

fsck: give accurate error message on empty loose object files
[git.git] / sha1_file.c
index 25f6965294fcc6bc440eda32187e0cc2b67e69d1..797b0634cefc1a354b4c6619461e483c64adc9af 100644 (file)
@@ -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);