Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/utility/safe_browsing/mac/udif.h" | 5 #include "chrome/utility/safe_browsing/mac/udif.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 #include <bzlib.h> | 8 #include <bzlib.h> |
| 9 #include <libkern/OSByteOrder.h> | 9 #include <libkern/OSByteOrder.h> |
| 10 #include <uuid/uuid.h> | 10 #include <uuid/uuid.h> |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 | 341 |
| 342 DISALLOW_COPY_AND_ASSIGN(UDIFBlockChunkReadStream); | 342 DISALLOW_COPY_AND_ASSIGN(UDIFBlockChunkReadStream); |
| 343 }; | 343 }; |
| 344 | 344 |
| 345 } // namespace | 345 } // namespace |
| 346 | 346 |
| 347 UDIFParser::UDIFParser(ReadStream* stream) | 347 UDIFParser::UDIFParser(ReadStream* stream) |
| 348 : stream_(stream), | 348 : stream_(stream), |
| 349 partition_names_(), | 349 partition_names_(), |
| 350 blocks_(), | 350 blocks_(), |
| 351 block_size_(kSectorSize) { | 351 block_size_(kSectorSize), |
| 352 } | 352 signature_blob_data_(nullptr), |
| 353 signature_blob_length_(0) {} | |
| 353 | 354 |
| 354 UDIFParser::~UDIFParser() {} | 355 UDIFParser::~UDIFParser() {} |
| 355 | 356 |
| 356 bool UDIFParser::Parse() { | 357 bool UDIFParser::Parse() { |
| 357 if (!ParseBlkx()) | 358 if (!ParseBlkx()) |
| 358 return false; | 359 return false; |
| 359 | 360 |
| 360 return true; | 361 return true; |
| 361 } | 362 } |
| 362 | 363 |
| 364 uint64_t UDIFParser::GetDmgSignatureLength() { | |
| 365 return signature_blob_length_; | |
| 366 } | |
| 367 | |
| 368 uint8_t* UDIFParser::GetDmgSignatureData() { | |
| 369 return signature_blob_data_; | |
| 370 } | |
| 371 | |
| 363 size_t UDIFParser::GetNumberOfPartitions() { | 372 size_t UDIFParser::GetNumberOfPartitions() { |
| 364 return blocks_.size(); | 373 return blocks_.size(); |
| 365 } | 374 } |
| 366 | 375 |
| 367 std::string UDIFParser::GetPartitionName(size_t part_number) { | 376 std::string UDIFParser::GetPartitionName(size_t part_number) { |
| 368 DCHECK_LT(part_number, partition_names_.size()); | 377 DCHECK_LT(part_number, partition_names_.size()); |
| 369 return partition_names_[part_number]; | 378 return partition_names_[part_number]; |
| 370 } | 379 } |
| 371 | 380 |
| 372 std::string UDIFParser::GetPartitionType(size_t part_number) { | 381 std::string UDIFParser::GetPartitionType(size_t part_number) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 550 << ", SectorCount = " << chunk->sector_count | 559 << ", SectorCount = " << chunk->sector_count |
| 551 << ", CompressOffset = " << chunk->compressed_offset | 560 << ", CompressOffset = " << chunk->compressed_offset |
| 552 << ", CompressLen = " << chunk->compressed_length; | 561 << ", CompressLen = " << chunk->compressed_length; |
| 553 } | 562 } |
| 554 } | 563 } |
| 555 | 564 |
| 556 blocks_.push_back(std::move(block)); | 565 blocks_.push_back(std::move(block)); |
| 557 partition_names_.push_back(partition_name); | 566 partition_names_.push_back(partition_name); |
| 558 } | 567 } |
| 559 | 568 |
| 569 // The offsets in the trailer could be garbage in DMGs that aren't signed. | |
| 570 // Need a sanity check that the DMG has legit values for these fields. | |
| 571 if (trailer.code_signature_length != 0 && trailer_start > 0 && | |
| 572 trailer.code_signature_offset + trailer.code_signature_length <= | |
|
Robert Sesek
2017/06/26 18:56:33
Use safe_numerics for this math. There are example
mortonm
2017/06/27 16:36:23
Done.
| |
| 573 (uint64_t)trailer_start) { | |
|
Robert Sesek
2017/06/26 18:56:33
C-style casts are banned by the styleguide.
mortonm
2017/06/27 16:36:23
Done.
| |
| 574 uint64_t temp_size = trailer.code_signature_length; | |
| 575 uint8_t* temp_data = new uint8_t[temp_size]; | |
|
Robert Sesek
2017/06/26 18:56:33
This is leaked. Rather than tracking size and byte
mortonm
2017/06/27 16:36:23
Done.
| |
| 576 | |
| 577 if (temp_data == nullptr) { | |
|
Robert Sesek
2017/06/26 18:56:33
This doesn't happen in Chromium (failure to alloca
mortonm
2017/06/27 16:36:23
So do you think I should put a cap on the size of
Robert Sesek
2017/06/28 18:21:06
I could see putting a cap on the signature_length,
mortonm
2017/06/28 23:07:08
As of now, if the metadata in trailer.code_signatu
| |
| 578 // If indicated signature size was too large for allocation, still want to | |
| 579 // continue processing DMG. | |
| 580 return true; | |
| 581 } | |
| 582 | |
| 583 off_t code_signature_start = | |
| 584 stream_->Seek(trailer.code_signature_offset, SEEK_SET); | |
| 585 if (code_signature_start == -1) | |
| 586 return false; | |
| 587 | |
| 588 size_t bytes_read = 0; | |
| 589 | |
| 590 if (!stream_->Read(temp_data, temp_size, &bytes_read)) { | |
|
Robert Sesek
2017/06/26 18:56:33
… and then using a vector, you std::vector<unit8_t
mortonm
2017/06/27 16:36:23
Done.
| |
| 591 DLOG(ERROR) << "Failed to read raw signature bytes"; | |
| 592 return false; | |
| 593 } | |
| 594 | |
| 595 if (bytes_read != temp_size) | |
| 596 return false; | |
| 597 | |
| 598 signature_blob_length_ = temp_size; | |
| 599 signature_blob_data_ = temp_data; | |
| 600 } | |
| 601 | |
| 560 return true; | 602 return true; |
| 561 } | 603 } |
| 562 | 604 |
| 563 namespace { | 605 namespace { |
| 564 | 606 |
| 565 UDIFPartitionReadStream::UDIFPartitionReadStream( | 607 UDIFPartitionReadStream::UDIFPartitionReadStream( |
| 566 ReadStream* stream, | 608 ReadStream* stream, |
| 567 uint16_t block_size, | 609 uint16_t block_size, |
| 568 const UDIFBlock* partition_block) | 610 const UDIFBlock* partition_block) |
| 569 : stream_(stream), | 611 : stream_(stream), |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 865 << chunk_->compressed_offset; | 907 << chunk_->compressed_offset; |
| 866 return false; | 908 return false; |
| 867 } | 909 } |
| 868 return true; | 910 return true; |
| 869 } | 911 } |
| 870 | 912 |
| 871 } // namespace | 913 } // namespace |
| 872 | 914 |
| 873 } // namespace dmg | 915 } // namespace dmg |
| 874 } // namespace safe_browsing | 916 } // namespace safe_browsing |
| OLD | NEW |