Index: third_party/android_crazy_linker/src/src/crazy_linker_zip.cpp |
diff --git a/third_party/android_crazy_linker/src/src/crazy_linker_zip.cpp b/third_party/android_crazy_linker/src/src/crazy_linker_zip.cpp |
index d0a2ff38284e5a491d42da6400b80649ba431c0a..089bb341db9f52cef89ac6ffbb79f7fdf81c6113 100644 |
--- a/third_party/android_crazy_linker/src/src/crazy_linker_zip.cpp |
+++ b/third_party/android_crazy_linker/src/src/crazy_linker_zip.cpp |
@@ -34,8 +34,11 @@ const int kOffsetOfStartOfCentralDirInEndOfCentralDirectory = |
const uint32_t kCentralDirHeaderMarker = 0x2014b50; |
// Offsets of fields in Central Directory Header. |
+const int kOffsetCompressedSizeInCentralDirectory = 4 + 2 + 2 + 2 + 2 + 2 + 2 + 4; |
+const int kOffsetUncompressedSizeInCentralDirectory = |
+ kOffsetCompressedSizeInCentralDirectory + 4; |
const int kOffsetFilenameLengthInCentralDirectory = |
- 4 + 2 + 2 + 2 + 2 + 2 + 2 + 4 + 4 + 4; |
+ kOffsetUncompressedSizeInCentralDirectory + 4; |
const int kOffsetExtraFieldLengthInCentralDirectory = |
kOffsetFilenameLengthInCentralDirectory + 2; |
const int kOffsetCommentLengthInCentralDirectory = |
@@ -97,13 +100,16 @@ namespace crazy { |
const uint32_t kMaxZipFileLength = 1U << 31; // 2GB |
-int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) { |
+ |
+OffsetSize FindStartOffsetAndLengthOfFileInZipFile(const char* zip_file, |
+ const char* filename) { |
+ OffsetSize result(CRAZY_OFFSET_FAILED, -1); |
// Open the file |
FileDescriptor fd; |
if (!fd.OpenReadOnly(zip_file)) { |
LOG_ERRNO("%s: open failed trying to open zip file %s\n", |
__FUNCTION__, zip_file); |
- return CRAZY_OFFSET_FAILED; |
+ return result; |
} |
// Find the length of the file. |
@@ -111,13 +117,13 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) { |
if (stat(zip_file, &stat_buf) == -1) { |
LOG_ERRNO("%s: stat failed trying to stat zip file %s\n", |
__FUNCTION__, zip_file); |
- return CRAZY_OFFSET_FAILED; |
+ return result; |
} |
if (stat_buf.st_size > kMaxZipFileLength) { |
LOG("%s: The size %ld of %s is too large to map\n", |
__FUNCTION__, stat_buf.st_size, zip_file); |
- return CRAZY_OFFSET_FAILED; |
+ return result; |
} |
// Map the file into memory. |
@@ -125,7 +131,7 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) { |
if (mem == MAP_FAILED) { |
LOG_ERRNO("%s: mmap failed trying to mmap zip file %s\n", |
__FUNCTION__, zip_file); |
- return CRAZY_OFFSET_FAILED; |
+ return result; |
} |
ScopedMMap scoped_mmap(mem, stat_buf.st_size); |
@@ -142,7 +148,7 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) { |
if (off == -1) { |
LOG("%s: Failed to find end of central directory in %s\n", |
__FUNCTION__, zip_file); |
- return CRAZY_OFFSET_FAILED; |
+ return result; |
} |
// We have located the end of central directory record, now locate |
@@ -156,14 +162,14 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) { |
if (start_of_central_dir > off) { |
LOG("%s: Found out of range offset %u for start of directory in %s\n", |
__FUNCTION__, start_of_central_dir, zip_file); |
- return CRAZY_OFFSET_FAILED; |
+ return result; |
} |
uint32_t end_of_central_dir = start_of_central_dir + length_of_central_dir; |
if (end_of_central_dir > off) { |
LOG("%s: Found out of range offset %u for end of directory in %s\n", |
__FUNCTION__, end_of_central_dir, zip_file); |
- return CRAZY_OFFSET_FAILED; |
+ return result; |
} |
uint32_t num_entries = ReadUInt16( |
@@ -179,8 +185,12 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) { |
LOG("%s: Failed to find central directory header marker in %s. " |
"Found 0x%x but expected 0x%x\n", __FUNCTION__, |
zip_file, marker, kCentralDirHeaderMarker); |
- return CRAZY_OFFSET_FAILED; |
+ return result; |
} |
+ uint32_t compressed_size = |
+ ReadUInt32(mem_bytes, off + kOffsetCompressedSizeInCentralDirectory); |
+ uint32_t uncompressed_size = |
+ ReadUInt32(mem_bytes, off + kOffsetUncompressedSizeInCentralDirectory); |
uint32_t file_name_length = |
ReadUInt16(mem_bytes, off + kOffsetFilenameLengthInCentralDirectory); |
uint32_t extra_field_length = |
@@ -204,7 +214,7 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) { |
LOG("%s: Failed to find local file header marker in %s. " |
"Found 0x%x but expected 0x%x\n", __FUNCTION__, |
zip_file, marker, kLocalHeaderMarker); |
- return CRAZY_OFFSET_FAILED; |
+ return result; |
} |
uint32_t compression_method = |
@@ -215,7 +225,13 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) { |
LOG("%s: %s is compressed within %s. " |
"Found compression method %u but expected %u\n", __FUNCTION__, |
filename, zip_file, compression_method, kCompressionMethodStored); |
- return CRAZY_OFFSET_FAILED; |
+ return result; |
+ } |
+ |
+ if (uncompressed_size != compressed_size) { |
+ LOG("%s: Uncompressed size (%d) differs from compressed size (%d).\n", |
+ __FUNCTION__, filename, uncompressed_size, compressed_size); |
+ return result; |
} |
uint32_t file_name_length = |
@@ -229,7 +245,9 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) { |
uint32_t header_length = |
kOffsetFilenameInLocalHeader + file_name_length + extra_field_length; |
- return local_header_offset + header_length; |
+ result.offset = local_header_offset + header_length; |
+ result.size = compressed_size; |
+ return result; |
} |
off += header_length; |
@@ -246,7 +264,12 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) { |
} |
LOG("%s: Did not find %s in %s\n", __FUNCTION__, filename, zip_file); |
- return CRAZY_OFFSET_FAILED; |
+ return result; |
+} |
+ |
+ |
+int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) { |
+ return FindStartOffsetAndLengthOfFileInZipFile(zip_file, filename).offset; |
} |
} // crazy namespace |