MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / ValidateDataDescriptor

Function ValidateDataDescriptor

Bcore/src/main/cpp/ziparchive/zip_archive.cc:460–490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

458}
459
460static int32_t ValidateDataDescriptor(MappedZipFile& mapped_zip, ZipEntry* entry) {
461 uint8_t ddBuf[sizeof(DataDescriptor) + sizeof(DataDescriptor::kOptSignature)];
462 off64_t offset = entry->offset;
463 if (entry->method != kCompressStored) {
464 offset += entry->compressed_length;
465 } else {
466 offset += entry->uncompressed_length;
467 }
468
469 if (!mapped_zip.ReadAtOffset(ddBuf, sizeof(ddBuf), offset)) {
470 return kIoError;
471 }
472
473 const uint32_t ddSignature = *(reinterpret_cast<const uint32_t*>(ddBuf));
474 const uint16_t ddOffset = (ddSignature == DataDescriptor::kOptSignature) ? 4 : 0;
475 const DataDescriptor* descriptor = reinterpret_cast<const DataDescriptor*>(ddBuf + ddOffset);
476
477 // Validate that the values in the data descriptor match those in the central
478 // directory.
479 if (entry->compressed_length != descriptor->compressed_size ||
480 entry->uncompressed_length != descriptor->uncompressed_size ||
481 entry->crc32 != descriptor->crc32) {
482 //chensenhua ALOGW("Zip: size/crc32 mismatch. expected {%" PRIu32 ", %" PRIu32 ", %" PRIx32
483 //chensenhua "}, was {%" PRIu32 ", %" PRIu32 ", %" PRIx32 "}",
484 //chensenhua entry->compressed_length, entry->uncompressed_length, entry->crc32,
485 //chensenhua descriptor->compressed_size, descriptor->uncompressed_size, descriptor->crc32);
486 return kInconsistentInformation;
487 }
488
489 return 0;
490}
491
492static int32_t FindEntry(const ZipArchive* archive, const int ent, ZipEntry* data) {
493 const uint16_t nameLen = archive->hash_table[ent].name_length;

Callers 1

ExtractToWriterFunction · 0.85

Calls 1

ReadAtOffsetMethod · 0.45

Tested by

no test coverage detected