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..dea3cf91ff766ea2cd5ef10a307b796bf151f9ac 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::GetCodeSignature() { |
+ return signature_blob_; |
+} |
+ |
size_t UDIFParser::GetNumberOfPartitions() { |
return blocks_.size(); |
} |
@@ -557,6 +560,37 @@ 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) { |
+ DLOG(ERROR) << "Read unexpected number of raw signature bytes"; |
+ return false; |
+ } |
+ } |
+ } |
+ |
return true; |
} |