Merge branch 'nd/cache-tree-api-refactor'
[gitweb.git] / sha1_file.c
index 88f2151ff31870138a53e40f99f5ae9928b09545..d9aa0e0a2cd45acbbe3beb6c015f5f9071a22902 100644 (file)
@@ -1202,6 +1202,11 @@ 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);