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

Side by Side Diff: components/precache/core/precache_manifest_util.cc

Issue 2820713002: precache: Add the check for a minimum length of manifest bitset. (Closed)
Patch Set: Created 3 years, 8 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/precache/core/precache_manifest_util.h" 5 #include "components/precache/core/precache_manifest_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "components/precache/core/proto/precache.pb.h" 9 #include "components/precache/core/proto/precache.pb.h"
10 10
(...skipping 18 matching lines...) Expand all
29 const PrecacheManifest& manifest, 29 const PrecacheManifest& manifest,
30 uint32_t experiment_id) { 30 uint32_t experiment_id) {
31 base::Optional<std::vector<bool>> ret; 31 base::Optional<std::vector<bool>> ret;
32 if (manifest.has_experiments()) { 32 if (manifest.has_experiments()) {
33 const auto& resource_bitset_map = 33 const auto& resource_bitset_map =
34 manifest.experiments().resources_by_experiment_group(); 34 manifest.experiments().resources_by_experiment_group();
35 const auto& it = resource_bitset_map.find(experiment_id); 35 const auto& it = resource_bitset_map.find(experiment_id);
36 if (it != resource_bitset_map.end()) { 36 if (it != resource_bitset_map.end()) {
37 if (it->second.has_bitset()) { 37 if (it->second.has_bitset()) {
38 const std::string& bitset = it->second.bitset(); 38 const std::string& bitset = it->second.bitset();
39 ret.emplace(bitset.size() * 8); 39 const int bitset_size = bitset.size() * 8;
40 for (size_t i = 0; i < bitset.size(); ++i) { 40 DCHECK_GE(bitset_size, manifest.resource_size());
41 for (size_t j = 0; j < 8; ++j) { 41 if (bitset_size >= manifest.resource_size()) {
42 if ((1 << j) & bitset[i]) 42 ret.emplace(bitset_size);
43 ret.value()[i * 8 + j] = true; 43 for (size_t i = 0; i < bitset.size(); ++i) {
44 for (size_t j = 0; j < 8; ++j) {
45 if ((1 << j) & bitset[i])
46 ret.value()[i * 8 + j] = true;
47 }
44 } 48 }
45 } 49 }
46 } else if (it->second.has_deprecated_bitset()) { 50 } else if (it->second.has_deprecated_bitset()) {
47 uint64_t bitset = it->second.deprecated_bitset(); 51 uint64_t bitset = it->second.deprecated_bitset();
48 ret.emplace(64); 52 DCHECK_GE(64, manifest.resource_size());
49 for (int i = 0; i < 64; ++i) { 53 if (64 >= manifest.resource_size()) {
50 if ((0x1ULL << i) & bitset) 54 ret.emplace(64);
51 ret.value()[i] = true; 55 for (int i = 0; i < 64; ++i) {
56 if ((0x1ULL << i) & bitset)
57 ret.value()[i] = true;
58 }
52 } 59 }
53 } 60 }
54 } 61 }
55 } 62 }
56 // Only return one variable to ensure RVO triggers. 63 // Only return one variable to ensure RVO triggers.
57 return ret; 64 return ret;
58 } 65 }
59 66
60 } // namespace precache 67 } // namespace precache
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698