diff --git a/base/mapped_file.cpp b/base/mapped_file.cpp index faa845d14..7c65dc3c5 100644 --- a/base/mapped_file.cpp +++ b/base/mapped_file.cpp @@ -41,7 +41,14 @@ std::unique_ptr MappedFile::FromFd(int fd, off64_t offset, size_t le HANDLE handle = CreateFileMapping(reinterpret_cast(_get_osfhandle(fd)), nullptr, (prot & PROT_WRITE) ? PAGE_READWRITE : PAGE_READONLY, 0, 0, nullptr); - if (handle == nullptr) return nullptr; + if (handle == nullptr) { + // http://b/119818070 "app crashes when reading asset of zero length". + // Return a MappedFile that's only valid for reading the size. + if (length == 0) { + return std::unique_ptr(new MappedFile{nullptr, 0, 0, nullptr}); + } + return nullptr; + } void* base = MapViewOfFile(handle, (prot & PROT_WRITE) ? FILE_MAP_ALL_ACCESS : FILE_MAP_READ, 0, file_offset, file_length); if (base == nullptr) {