Merge "ZipWriter: Keep LFH and CFH in sync" into oc-dev am: d4c8d87a9b

am: 2e79e7a439

Change-Id: If89c0645d15fa758e31b179ceedbce3296b5f49a
This commit is contained in:
Adam Lesinski 2017-04-11 02:17:48 +00:00 committed by android-build-merger
commit 89caf0bb1f
2 changed files with 14 additions and 1 deletions

View File

@ -576,6 +576,17 @@ static int32_t FindEntry(const ZipArchive* archive, const int ent,
// Paranoia: Match the values specified in the local file header
// to those specified in the central directory.
// Verify that the central directory and local file header agree on the use of a trailing
// Data Descriptor.
if ((lfh->gpb_flags & kGPBDDFlagMask) != (cdr->gpb_flags & kGPBDDFlagMask)) {
ALOGW("Zip: gpb flag mismatch. expected {%04" PRIx16 "}, was {%04" PRIx16 "}",
cdr->gpb_flags, lfh->gpb_flags);
return kInconsistentInformation;
}
// If there is no trailing data descriptor, verify that the central directory and local file
// header agree on the crc, compressed, and uncompressed sizes of the entry.
if ((lfh->gpb_flags & kGPBDDFlagMask) == 0) {
data->has_data_descriptor = 0;
if (data->compressed_length != lfh->compressed_size

View File

@ -479,7 +479,9 @@ int32_t ZipWriter::Finish() {
for (FileEntry& file : files_) {
CentralDirectoryRecord cdr = {};
cdr.record_signature = CentralDirectoryRecord::kSignature;
cdr.gpb_flags |= kGPBDDFlagMask;
if ((file.compression_method & kCompressDeflated) || !seekable_) {
cdr.gpb_flags |= kGPBDDFlagMask;
}
cdr.compression_method = file.compression_method;
cdr.last_mod_time = file.last_mod_time;
cdr.last_mod_date = file.last_mod_date;