crazy linker: Alter search for zip EOCD start

When loading directly from APK, begin searching backwards
for the zip EOCD record signature at size of EOCD record
bytes before the end of the file.

BUG=537205
R=rmcilroy@chromium.org

Review URL: https://codereview.chromium.org/1390553002 .

Cr-Commit-Position: refs/heads/master@{#352577}
diff --git a/third_party/android_crazy_linker/README.chromium b/third_party/android_crazy_linker/README.chromium
index 9400fbd..ebf53d1 100644
--- a/third_party/android_crazy_linker/README.chromium
+++ b/third_party/android_crazy_linker/README.chromium
@@ -86,3 +86,5 @@
 
 - Remove CVE-2011-1149 detection machinery.
 
+- Start zip EOCD signature search at size of EOCD record bytes from file end.
+
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 d0a2ff3..762075f 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
@@ -22,6 +22,12 @@
 // This marker appears at the start of the end of central directory record
 const uint32_t kEndOfCentralDirectoryMarker = 0x06054b50;
 
+// Length of the end of central directory record, the point back from the
+// end of file at which we start to scan backwards for the end of central
+// directory marker
+const uint32_t kEndOfCentralDirectoryRecordSize =
+    4 + 2 + 2 + 2 + 2 + 4 + 4 + 2;
+
 // Offsets of fields in End of Central Directory.
 const int kOffsetNumOfEntriesInEndOfCentralDirectory = 4 + 2 + 2;
 const int kOffsetOfCentralDirLengthInEndOfCentralDirectory =
@@ -130,11 +136,12 @@
   ScopedMMap scoped_mmap(mem, stat_buf.st_size);
 
   // Scan backwards from the end of the file searching for the end of
-  // central directory marker.
+  // central directory marker. The earliest occurrence we accept is
+  // size of end of central directory bytes back from from the end of the
+  // file.
   uint8_t* mem_bytes = static_cast<uint8_t*>(mem);
-  int off;
-  for (off = stat_buf.st_size - sizeof(kEndOfCentralDirectoryMarker);
-       off >= 0; --off) {
+  int off = stat_buf.st_size - kEndOfCentralDirectoryRecordSize;
+  for (; off >= 0; --off) {
     if (ReadUInt32(mem_bytes, off) == kEndOfCentralDirectoryMarker) {
       break;
     }