Chromium Code Reviews| Index: chrome/utility/safe_browsing/mac/udif.cc |
| diff --git a/chrome/utility/safe_browsing/mac/udif.cc b/chrome/utility/safe_browsing/mac/udif.cc |
| index 0c4be3fa310747ef84226969a5ea536f630e8b6c..1e5d1b85ce913b3d32767cfb4a16699dd6e81a1a 100644 |
| --- a/chrome/utility/safe_browsing/mac/udif.cc |
| +++ b/chrome/utility/safe_browsing/mac/udif.cc |
| @@ -348,8 +348,7 @@ UDIFParser::UDIFParser(ReadStream* stream) |
| : stream_(stream), |
| partition_names_(), |
| blocks_(), |
| - block_size_(kSectorSize) { |
| -} |
| + block_size_(kSectorSize) {} |
| UDIFParser::~UDIFParser() {} |
| @@ -360,6 +359,10 @@ bool UDIFParser::Parse() { |
| return true; |
| } |
| +const std::vector<uint8_t>& UDIFParser::GetDmgSignatureData() { |
| + return signature_blob_; |
| +} |
| + |
| size_t UDIFParser::GetNumberOfPartitions() { |
| return blocks_.size(); |
| } |
| @@ -557,6 +560,35 @@ bool UDIFParser::ParseBlkx() { |
| partition_names_.push_back(partition_name); |
| } |
| + // The offsets in the trailer could be garbage in DMGs that aren't signed. |
| + // Need a sanity check that the DMG has legit values for these fields. |
| + if (trailer.code_signature_length != 0 && trailer_start > 0) { |
| + auto code_signature_end = |
| + base::CheckedNumeric<size_t>(trailer.code_signature_offset) + |
| + trailer.code_signature_length; |
| + if (code_signature_end.IsValid() && |
| + code_signature_end.ValueOrDie() <= |
| + base::checked_cast<size_t>(trailer_start)) { |
| + signature_blob_.resize(trailer.code_signature_length); |
| + |
| + off_t code_signature_start = |
| + stream_->Seek(trailer.code_signature_offset, SEEK_SET); |
| + if (code_signature_start == -1) |
| + return false; |
| + |
| + size_t bytes_read = 0; |
| + |
| + if (!stream_->Read(signature_blob_.data(), trailer.code_signature_length, |
| + &bytes_read)) { |
| + DLOG(ERROR) << "Failed to read raw signature bytes"; |
| + return false; |
| + } |
| + |
| + if (bytes_read != trailer.code_signature_length) |
|
Robert Sesek
2017/06/28 18:21:06
DLOGing here would be helpful too, I think.
mortonm
2017/06/28 23:07:09
Done.
|
| + return false; |
| + } |
| + } |
| + |
| return true; |
| } |