OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" | |
6 | |
7 #include "base/strings/string_number_conversions.h" | |
8 #include "base/strings/utf_string_conversions.h" | |
9 #include "net/http/http_status_code.h" | |
10 #include "net/url_request/url_fetcher.h" | |
11 #include "net/url_request/url_request_context_getter.h" | |
12 #include "third_party/smhasher/src/MurmurHash2.h" | |
13 #include "url/gurl.h" | |
14 | |
15 namespace { | |
16 | |
17 // The seed to use when taking the murmur2 hash of the icon. | |
18 const uint64_t kMurmur2HashSeed = 0; | |
19 | |
20 } // anonymous namespace | |
21 | |
22 WebApkIconHasher::WebApkIconHasher() {} | |
23 | |
24 WebApkIconHasher::~WebApkIconHasher() {} | |
25 | |
26 void WebApkIconHasher::DownloadAndGetMurmur2Hash( | |
27 net::URLRequestContextGetter* request_context_getter, | |
28 const GURL& icon_url, | |
29 const Murmur2HashCallback& callback) { | |
30 callback_ = callback; | |
31 | |
32 url_fetcher_ = net::URLFetcher::Create(icon_url, net::URLFetcher::GET, this); | |
33 url_fetcher_->SetRequestContext(request_context_getter); | |
34 url_fetcher_->Start(); | |
35 } | |
36 | |
37 void WebApkIconHasher::OnURLFetchComplete(const net::URLFetcher* source) { | |
38 if (!source->GetStatus().is_success() || | |
39 source->GetResponseCode() != net::HTTP_OK) { | |
40 callback_.Run(""); | |
41 return; | |
42 } | |
43 | |
44 // WARNING: We are running in the browser process. |raw_image_data| is the | |
Robert Sesek
2016/08/16 19:55:57
Thanks for the security-conscious comment!
| |
45 // image's raw, unsanitized bytes from the web. |raw_image_data| may contain | |
46 // malicious data. Decoding unsanitized bitmap data to an SkBitmap in the | |
47 // browser process is a security bug. | |
48 std::string raw_image_data; | |
49 source->GetResponseAsString(&raw_image_data); | |
50 uint64_t hash = MurmurHash64B(&raw_image_data.front(), raw_image_data.size(), | |
51 kMurmur2HashSeed); | |
52 callback_.Run(base::Uint64ToString(hash)); | |
53 } | |
OLD | NEW |