Fix entry handling for 0 length entries.

Two minor issues were fixed:
- The offset to entry data can be the same as the
  central directory offset when the last entry in the
  file has length 0 and is stored (not deflated). Fix
  a check that disallowed this. We already have a strict
  check that entry data must end before the central directory,
  so we're covered.
- We would attempt to map a segment of length 0 when writing
  an entry whose length is 0. We should just return early in
  this case.

bug: 12623277
Change-Id: I2a4ca0c4d170cc3cbf326e5ca13894acd9c434c9
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc
index 8436d49..a23d4ae 100644
--- a/libziparchive/zip_archive.cc
+++ b/libziparchive/zip_archive.cc
@@ -756,7 +756,7 @@
   }
 
   const off64_t data_offset = local_header_offset + kLFHLen + lfhNameLen + lfhExtraLen;
-  if (data_offset >= cd_offset) {
+  if (data_offset > cd_offset) {
     ALOGW("Zip: bad data offset %lld in zip", (off64_t) data_offset);
     return kInvalidOffset;
   }
@@ -1021,6 +1021,13 @@
     return kIoError;
   }
 
+  // Don't attempt to map a region of length 0. We still need the
+  // ftruncate() though, since the API guarantees that we will truncate
+  // the file to the end of the uncompressed output.
+  if (declared_length == 0) {
+      return 0;
+  }
+
   android::FileMap* map  = MapFileSegment(fd, current_offset, declared_length,
                                           false, kTempMappingFileName);
   if (map == NULL) {