X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=sha1_file.c;h=d9aa0e0a2cd45acbbe3beb6c015f5f9071a22902;hb=471dcfdbb23ad423168d928335bc36217f9e311d;hp=88f2151ff31870138a53e40f99f5ae9928b09545;hpb=c4a01a3cbbd8b642a3ffc6bc550b68ac63d500ed;p=git.git diff --git a/sha1_file.c b/sha1_file.c index 88f2151ff..d9aa0e0a2 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -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);