Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service.cc

Issue 1827303002: Report and parse .img, .iso, and .smi as DMGs when downloading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix namespacing Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/common/safe_browsing/download_protection_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/safe_browsing/download_protection_service.h" 5 #include "chrome/browser/safe_browsing/download_protection_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 RecordFileExtensionType(item_->GetTargetFilePath()); 328 RecordFileExtensionType(item_->GetTargetFilePath());
329 329
330 // Compute features from the file contents. Note that we record histograms 330 // Compute features from the file contents. Note that we record histograms
331 // based on the result, so this runs regardless of whether the pingbacks 331 // based on the result, so this runs regardless of whether the pingbacks
332 // are enabled. 332 // are enabled.
333 if (item_->GetTargetFilePath().MatchesExtension( 333 if (item_->GetTargetFilePath().MatchesExtension(
334 FILE_PATH_LITERAL(".zip"))) { 334 FILE_PATH_LITERAL(".zip"))) {
335 StartExtractZipFeatures(); 335 StartExtractZipFeatures();
336 #if defined(OS_MACOSX) 336 #if defined(OS_MACOSX)
337 } else if (item_->GetTargetFilePath().MatchesExtension( 337 } else if (item_->GetTargetFilePath().MatchesExtension(
338 FILE_PATH_LITERAL(".dmg"))) { 338 FILE_PATH_LITERAL(".dmg")) ||
339 item_->GetTargetFilePath().MatchesExtension(
340 FILE_PATH_LITERAL(".img")) ||
341 item_->GetTargetFilePath().MatchesExtension(
342 FILE_PATH_LITERAL(".iso")) ||
343 item_->GetTargetFilePath().MatchesExtension(
344 FILE_PATH_LITERAL(".smi"))) {
339 StartExtractDmgFeatures(); 345 StartExtractDmgFeatures();
340 #endif 346 #endif
341 } else { 347 } else {
342 StartExtractFileFeatures(); 348 StartExtractFileFeatures();
343 } 349 }
344 } 350 }
345 351
346 // Start a timeout to cancel the request if it takes too long. 352 // Start a timeout to cancel the request if it takes too long.
347 // This should only be called after we have finished accessing the file. 353 // This should only be called after we have finished accessing the file.
348 void StartTimeout() { 354 void StartTimeout() {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 // Normal zip w/o EXEs, or invalid zip and not extended-reporting. 624 // Normal zip w/o EXEs, or invalid zip and not extended-reporting.
619 PostFinishTask(UNKNOWN, REASON_ARCHIVE_WITHOUT_BINARIES); 625 PostFinishTask(UNKNOWN, REASON_ARCHIVE_WITHOUT_BINARIES);
620 return; 626 return;
621 } 627 }
622 } 628 }
623 629
624 OnFileFeatureExtractionDone(); 630 OnFileFeatureExtractionDone();
625 } 631 }
626 632
627 #if defined(OS_MACOSX) 633 #if defined(OS_MACOSX)
634 // This is called for .DMGs and other files that can be parsed by
635 // SandboxedDMGAnalyzer.
628 void StartExtractDmgFeatures() { 636 void StartExtractDmgFeatures() {
629 DCHECK_CURRENTLY_ON(BrowserThread::UI); 637 DCHECK_CURRENTLY_ON(BrowserThread::UI);
630 DCHECK(item_); 638 DCHECK(item_);
631 dmg_analyzer_ = new SandboxedDMGAnalyzer( 639 dmg_analyzer_ = new SandboxedDMGAnalyzer(
632 item_->GetFullPath(), 640 item_->GetFullPath(),
633 base::Bind(&CheckClientDownloadRequest::OnDmgAnalysisFinished, 641 base::Bind(&CheckClientDownloadRequest::OnDmgAnalysisFinished,
634 weakptr_factory_.GetWeakPtr())); 642 weakptr_factory_.GetWeakPtr()));
635 dmg_analyzer_->Start(); 643 dmg_analyzer_->Start();
636 dmg_analysis_start_time_ = base::TimeTicks::Now(); 644 dmg_analysis_start_time_ = base::TimeTicks::Now();
637 } 645 }
638 646
639 void OnDmgAnalysisFinished(const zip_analyzer::Results& results) { 647 void OnDmgAnalysisFinished(const zip_analyzer::Results& results) {
640 DCHECK_CURRENTLY_ON(BrowserThread::UI); 648 DCHECK_CURRENTLY_ON(BrowserThread::UI);
641 DCHECK_EQ(ClientDownloadRequest::MAC_EXECUTABLE, type_); 649 DCHECK_EQ(ClientDownloadRequest::MAC_EXECUTABLE, type_);
642 if (!service_) 650 if (!service_)
643 return; 651 return;
644 652
645 // Even if !results.success, some of the DMG may have been parsed. 653 // Even if !results.success, some of the DMG may have been parsed.
646 archive_is_valid_ = 654 archive_is_valid_ =
647 (results.success ? ArchiveValid::VALID : ArchiveValid::INVALID); 655 (results.success ? ArchiveValid::VALID : ArchiveValid::INVALID);
648 archived_executable_ = results.has_executable; 656 archived_executable_ = results.has_executable;
649 archived_binary_.CopyFrom(results.archived_binary); 657 archived_binary_.CopyFrom(results.archived_binary);
650 DVLOG(1) << "DMG analysis has finished for " << item_->GetFullPath().value() 658 DVLOG(1) << "DMG analysis has finished for " << item_->GetFullPath().value()
651 << ", has_executable=" << results.has_executable 659 << ", has_executable=" << results.has_executable
652 << ", success=" << results.success; 660 << ", success=" << results.success;
653 661
654 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.DmgFileSuccess", results.success); 662 int uma_file_type =
655 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.DmgFileHasExecutable", 663 download_protection_util::GetSBClientDownloadExtensionValueForUMA(
656 archived_executable_); 664 item_->GetTargetFilePath());
665
666 if (results.success) {
667 UMA_HISTOGRAM_SPARSE_SLOWLY("SBClientDownload.DmgFileSuccessByType",
668 uma_file_type);
669 } else {
670 UMA_HISTOGRAM_SPARSE_SLOWLY("SBClientDownload.DmgFileFailureByType",
671 uma_file_type);
672 }
673
674 if (archived_executable_) {
675 UMA_HISTOGRAM_SPARSE_SLOWLY("SBClientDownload.DmgFileHasExecutableByType",
676 uma_file_type);
677 } else {
678 UMA_HISTOGRAM_SPARSE_SLOWLY(
679 "SBClientDownload.DmgFileHasNoExecutableByType", uma_file_type);
680 }
681
657 UMA_HISTOGRAM_TIMES("SBClientDownload.ExtractDmgFeaturesTime", 682 UMA_HISTOGRAM_TIMES("SBClientDownload.ExtractDmgFeaturesTime",
658 base::TimeTicks::Now() - dmg_analysis_start_time_); 683 base::TimeTicks::Now() - dmg_analysis_start_time_);
659 684
660 if (!archived_executable_) { 685 if (!archived_executable_) {
661 if (!results.success && CanReportInvalidArchives()) { 686 if (!results.success && CanReportInvalidArchives()) {
662 type_ = ClientDownloadRequest::INVALID_MAC_ARCHIVE; 687 type_ = ClientDownloadRequest::INVALID_MAC_ARCHIVE;
663 } else { 688 } else {
664 PostFinishTask(UNKNOWN, REASON_ARCHIVE_WITHOUT_BINARIES); 689 PostFinishTask(UNKNOWN, REASON_ARCHIVE_WITHOUT_BINARIES);
665 return; 690 return;
666 } 691 }
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 GURL DownloadProtectionService::GetDownloadRequestUrl() { 1279 GURL DownloadProtectionService::GetDownloadRequestUrl() {
1255 GURL url(kDownloadRequestUrl); 1280 GURL url(kDownloadRequestUrl);
1256 std::string api_key = google_apis::GetAPIKey(); 1281 std::string api_key = google_apis::GetAPIKey();
1257 if (!api_key.empty()) 1282 if (!api_key.empty())
1258 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); 1283 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true));
1259 1284
1260 return url; 1285 return url;
1261 } 1286 }
1262 1287
1263 } // namespace safe_browsing 1288 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | chrome/common/safe_browsing/download_protection_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698