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

Unified Diff: chrome/browser/safe_browsing/client_side_detection_service.cc

Issue 7465101: Check that all the hashes ids in the model are valid. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Avoid implicit conversion from double to float. Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/client_side_detection_service.cc
diff --git a/chrome/browser/safe_browsing/client_side_detection_service.cc b/chrome/browser/safe_browsing/client_side_detection_service.cc
index 878d49e45d8f3c5708e8606904f9842bbbbac6ae..fd5f59f76aeef3c0d3594b962e7812ed62a42b76 100644
--- a/chrome/browser/safe_browsing/client_side_detection_service.cc
+++ b/chrome/browser/safe_browsing/client_side_detection_service.cc
@@ -299,6 +299,8 @@ void ClientSideDetectionService::HandleModelResponse(
model_status = MODEL_PARSE_ERROR;
} else if (!model->IsInitialized() || !model->has_version()) {
model_status = MODEL_MISSING_FIELDS;
+ } else if (!ModelHasValidHashIds(*model)) {
+ model_status = MODEL_BAD_HASH_IDS;
} else if (model->version() < 0 ||
(model_.get() && model->version() < model_->version())) {
model_status = MODEL_INVALID_VERSION_NUMBER;
@@ -459,4 +461,29 @@ void ClientSideDetectionService::SetBadSubnets(const ClientSideModel& model,
(*bad_subnets)[mask].insert(model.bad_subnet(i).prefix());
}
}
+
+/* static */
mattm 2011/08/03 20:46:55 // style comments
noelutz 2011/08/03 20:51:53 Done.
+bool ClientSideDetectionService::ModelHasValidHashIds(
+ const ClientSideModel& model) {
+ const int kMaxIndex = model.hashes_size() - 1;
mattm 2011/08/03 20:46:55 max_index
noelutz 2011/08/03 20:51:53 Done.
+ for (int i = 0; i < model.rule_size(); ++i) {
+ for (int j = 0; j < model.rule(i).feature_size(); ++j) {
+ if (model.rule(i).feature(j) < 0 ||
+ model.rule(i).feature(j) > kMaxIndex) {
+ return false;
+ }
+ }
+ }
+ for (int i = 0; i < model.page_term_size(); ++i) {
+ if (model.page_term(i) < 0 || model.page_term(i) > kMaxIndex) {
+ return false;
+ }
+ }
+ for (int i = 0; i < model.page_word_size(); ++i) {
+ if (model.page_word(i) < 0 || model.page_word(i) > kMaxIndex) {
+ return false;
+ }
+ }
+ return true;
+}
} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698