From f6fe9b6dabced73d5bc61a86dbf60cb060bc2d04 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Mon, 24 Sep 2018 12:13:31 -0700 Subject: [PATCH] Use empty data if file in zip has length 0 Mmap fails when the length of a file in a zip is 0, so use an aapt::io::EmptyData when the file length is 0. Bug: 113094267 Test: manual Change-Id: I2c1071293bf9b0fe33e8c279c8d78ff906fba5d6 --- tools/aapt2/io/ZipArchive.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/aapt2/io/ZipArchive.cpp b/tools/aapt2/io/ZipArchive.cpp index 8e6d7137640aa..866e96d56f972 100644 --- a/tools/aapt2/io/ZipArchive.cpp +++ b/tools/aapt2/io/ZipArchive.cpp @@ -33,6 +33,11 @@ ZipFile::ZipFile(ZipArchiveHandle handle, const ZipEntry& entry, : zip_handle_(handle), zip_entry_(entry), source_(source) {} std::unique_ptr ZipFile::OpenAsData() { + // The file will fail to be mmaped if it is empty + if (zip_entry_.uncompressed_length == 0) { + return util::make_unique(); + } + if (zip_entry_.method == kCompressStored) { int fd = GetFileDescriptor(zip_handle_);