| 441 | } |
| 442 | |
| 443 | bool DexFileVerifier::CheckMap() { |
| 444 | const DexFile::MapList* map = reinterpret_cast<const DexFile::MapList*>(begin_ + |
| 445 | header_->map_off_); |
| 446 | // Check that map list content is available. |
| 447 | if (!CheckListSize(map, 1, sizeof(DexFile::MapList), "maplist content")) { |
| 448 | return false; |
| 449 | } |
| 450 | |
| 451 | const DexFile::MapItem* item = map->list_; |
| 452 | |
| 453 | uint32_t count = map->size_; |
| 454 | uint32_t last_offset = 0; |
| 455 | uint32_t last_type = 0; |
| 456 | uint32_t data_item_count = 0; |
| 457 | uint32_t data_items_left = header_->data_size_; |
| 458 | uint32_t used_bits = 0; |
| 459 | |
| 460 | // Sanity check the size of the map list. |
| 461 | if (!CheckListSize(item, count, sizeof(DexFile::MapItem), "map size")) { |
| 462 | return false; |
| 463 | } |
| 464 | |
| 465 | // Check the items listed in the map. |
| 466 | for (uint32_t i = 0; i < count; i++) { |
| 467 | if (UNLIKELY(last_offset >= item->offset_ && i != 0)) { |
| 468 | ErrorStringPrintf("Out of order map item: %x then %x for type %x last type was %x", |
| 469 | last_offset, |
| 470 | item->offset_, |
| 471 | static_cast<uint32_t>(item->type_), |
| 472 | last_type); |
| 473 | return false; |
| 474 | } |
| 475 | if (UNLIKELY(item->offset_ >= header_->file_size_)) { |
| 476 | ErrorStringPrintf("Map item after end of file: %x, size %x", |
| 477 | item->offset_, header_->file_size_); |
| 478 | return false; |
| 479 | } |
| 480 | |
| 481 | DexFile::MapItemType item_type = static_cast<DexFile::MapItemType>(item->type_); |
| 482 | if (IsDataSectionType(item_type)) { |
| 483 | uint32_t icount = item->size_; |
| 484 | if (UNLIKELY(icount > data_items_left)) { |
| 485 | ErrorStringPrintf("Too many items in data section: %ud item_type %zx", |
| 486 | data_item_count + icount, |
| 487 | static_cast<size_t>(item_type)); |
| 488 | return false; |
| 489 | } |
| 490 | data_items_left -= icount; |
| 491 | data_item_count += icount; |
| 492 | } |
| 493 | |
| 494 | uint32_t bit = MapTypeToBitMask(item_type); |
| 495 | |
| 496 | if (UNLIKELY(bit == 0)) { |
| 497 | ErrorStringPrintf("Unknown map section type %x", item->type_); |
| 498 | return false; |
| 499 | } |
| 500 |
nothing calls this directly
no test coverage detected