diff options
author | Pirama Arumuga Nainar <pirama@google.com> | 2019-03-07 16:12:55 -0800 |
---|---|---|
committer | Pirama Arumuga Nainar <pirama@google.com> | 2019-03-07 16:12:55 -0800 |
commit | 5d7f84144d04a9c145a44de3146b43b0119b3625 (patch) | |
tree | 13cb035ce0544a825995754b06a00305527317d5 /base/mapped_file.cpp | |
parent | 2ba61b775a568e15153e443a58e66217152792e1 (diff) | |
download | system_core-5d7f84144d04a9c145a44de3146b43b0119b3625.tar.gz system_core-5d7f84144d04a9c145a44de3146b43b0119b3625.tar.bz2 system_core-5d7f84144d04a9c145a44de3146b43b0119b3625.zip |
Support zero-length mapped files
Bug: http://b/119818070 "app crashes when reading asset of zero length"
Add support for zero-length mappings for the Windows code path as well.
Test: ran libbase_test on Windows under wine.
Change-Id: Iccb65fa800c636444100c9369f41e36d24a53a99
Diffstat (limited to 'base/mapped_file.cpp')
-rw-r--r-- | base/mapped_file.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
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> MappedFile::FromFd(int fd, off64_t offset, size_t le HANDLE handle = CreateFileMapping(reinterpret_cast<HANDLE>(_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<MappedFile>(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) { |