diff options
-rw-r--r-- | sha1_file.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c index 25f6965294..797b0634ce 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); |