X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=sha1_file.c;h=d9aa0e0a2cd45acbbe3beb6c015f5f9071a22902;hb=c6a4e3f7a78011bd7c1c75521c6d12ac311513f7;hp=88f2151ff31870138a53e40f99f5ae9928b09545;hpb=f342afafceb16b29a9b8718c5f42afaaf6291d78;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);