OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/subresource_filter/core/common/unindexed_ruleset.h" | 5 #include "components/subresource_filter/core/common/unindexed_ruleset.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/numerics/safe_conversions.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "components/subresource_filter/core/common/proto/rules.pb.h" | 14 #include "components/subresource_filter/core/common/proto/rules.pb.h" |
14 #include "components/subresource_filter/core/common/url_pattern.h" | 15 #include "components/subresource_filter/core/common/url_pattern.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h" | 17 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h" |
17 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" | 18 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" |
18 | 19 |
19 namespace subresource_filter { | 20 namespace subresource_filter { |
20 | 21 |
21 namespace { | 22 namespace { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 const std::vector<proto::UrlRule>& expected_url_rules) { | 116 const std::vector<proto::UrlRule>& expected_url_rules) { |
116 google::protobuf::io::ArrayInputStream array_input(ruleset_contents.data(), | 117 google::protobuf::io::ArrayInputStream array_input(ruleset_contents.data(), |
117 ruleset_contents.size()); | 118 ruleset_contents.size()); |
118 UnindexedRulesetReader reader(&array_input); | 119 UnindexedRulesetReader reader(&array_input); |
119 proto::FilteringRules chunk; | 120 proto::FilteringRules chunk; |
120 std::vector<proto::UrlRule> read_rules; | 121 std::vector<proto::UrlRule> read_rules; |
121 while (reader.ReadNextChunk(&chunk)) { | 122 while (reader.ReadNextChunk(&chunk)) { |
122 read_rules.insert(read_rules.end(), chunk.url_rules().begin(), | 123 read_rules.insert(read_rules.end(), chunk.url_rules().begin(), |
123 chunk.url_rules().end()); | 124 chunk.url_rules().end()); |
124 } | 125 } |
| 126 if (base::checked_cast<size_t>(reader.num_bytes_read()) != |
| 127 ruleset_contents.size()) { |
| 128 return false; |
| 129 } |
125 | 130 |
126 if (expected_url_rules.size() != read_rules.size()) | 131 if (expected_url_rules.size() != read_rules.size()) |
127 return false; | 132 return false; |
128 for (size_t i = 0, size = read_rules.size(); i != size; ++i) { | 133 for (size_t i = 0, size = read_rules.size(); i != size; ++i) { |
129 if (!IsEqual(expected_url_rules[i], read_rules[i])) | 134 if (!IsEqual(expected_url_rules[i], read_rules[i])) |
130 return false; | 135 return false; |
131 } | 136 } |
132 return true; | 137 return true; |
133 } | 138 } |
134 | 139 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 194 |
190 { | 195 { |
191 std::string ruleset_contents = builder.ruleset_contents(); | 196 std::string ruleset_contents = builder.ruleset_contents(); |
192 ASSERT_GT(ruleset_contents.size(), static_cast<size_t>(100)); | 197 ASSERT_GT(ruleset_contents.size(), static_cast<size_t>(100)); |
193 ruleset_contents.resize(100); | 198 ruleset_contents.resize(100); |
194 EXPECT_FALSE(IsRulesetValid(ruleset_contents, builder.url_rules())); | 199 EXPECT_FALSE(IsRulesetValid(ruleset_contents, builder.url_rules())); |
195 } | 200 } |
196 } | 201 } |
197 | 202 |
198 } // namespace subresource_filter | 203 } // namespace subresource_filter |
OLD | NEW |