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

Side by Side 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, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/client_side_detection_service.h" 5 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if (!status.is_success() || RC_REQUEST_OK != response_code) { 292 if (!status.is_success() || RC_REQUEST_OK != response_code) {
293 model_status = MODEL_FETCH_FAILED; 293 model_status = MODEL_FETCH_FAILED;
294 } else if (data.empty()) { 294 } else if (data.empty()) {
295 model_status = MODEL_EMPTY; 295 model_status = MODEL_EMPTY;
296 } else if (data.size() > kMaxModelSizeBytes) { 296 } else if (data.size() > kMaxModelSizeBytes) {
297 model_status = MODEL_TOO_LARGE; 297 model_status = MODEL_TOO_LARGE;
298 } else if (!model->ParseFromString(data)) { 298 } else if (!model->ParseFromString(data)) {
299 model_status = MODEL_PARSE_ERROR; 299 model_status = MODEL_PARSE_ERROR;
300 } else if (!model->IsInitialized() || !model->has_version()) { 300 } else if (!model->IsInitialized() || !model->has_version()) {
301 model_status = MODEL_MISSING_FIELDS; 301 model_status = MODEL_MISSING_FIELDS;
302 } else if (!ModelHasValidHashIds(*model)) {
303 model_status = MODEL_BAD_HASH_IDS;
302 } else if (model->version() < 0 || 304 } else if (model->version() < 0 ||
303 (model_.get() && model->version() < model_->version())) { 305 (model_.get() && model->version() < model_->version())) {
304 model_status = MODEL_INVALID_VERSION_NUMBER; 306 model_status = MODEL_INVALID_VERSION_NUMBER;
305 } else if (model_.get() && model->version() == model_->version()) { 307 } else if (model_.get() && model->version() == model_->version()) {
306 model_status = MODEL_NOT_CHANGED; 308 model_status = MODEL_NOT_CHANGED;
307 } else { 309 } else {
308 // The model is valid => replace the existing model with the new one. 310 // The model is valid => replace the existing model with the new one.
309 model_str_.assign(data); 311 model_str_.assign(data);
310 model_.swap(model); 312 model_.swap(model);
311 model_status = MODEL_SUCCESS; 313 model_status = MODEL_SUCCESS;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 // Basically we need to create a 16B long string which has the highest 454 // Basically we need to create a 16B long string which has the highest
453 // |size| bits sets to one. 455 // |size| bits sets to one.
454 std::string mask(net::kIPv6AddressSize, '\x00'); 456 std::string mask(net::kIPv6AddressSize, '\x00');
455 mask.replace(0, size / 8, size / 8, '\xFF'); 457 mask.replace(0, size / 8, size / 8, '\xFF');
456 if (size % 8) { 458 if (size % 8) {
457 mask[size / 8] = 0xFF << (8 - (size % 8)); 459 mask[size / 8] = 0xFF << (8 - (size % 8));
458 } 460 }
459 (*bad_subnets)[mask].insert(model.bad_subnet(i).prefix()); 461 (*bad_subnets)[mask].insert(model.bad_subnet(i).prefix());
460 } 462 }
461 } 463 }
464
465 /* static */
mattm 2011/08/03 20:46:55 // style comments
noelutz 2011/08/03 20:51:53 Done.
466 bool ClientSideDetectionService::ModelHasValidHashIds(
467 const ClientSideModel& model) {
468 const int kMaxIndex = model.hashes_size() - 1;
mattm 2011/08/03 20:46:55 max_index
noelutz 2011/08/03 20:51:53 Done.
469 for (int i = 0; i < model.rule_size(); ++i) {
470 for (int j = 0; j < model.rule(i).feature_size(); ++j) {
471 if (model.rule(i).feature(j) < 0 ||
472 model.rule(i).feature(j) > kMaxIndex) {
473 return false;
474 }
475 }
476 }
477 for (int i = 0; i < model.page_term_size(); ++i) {
478 if (model.page_term(i) < 0 || model.page_term(i) > kMaxIndex) {
479 return false;
480 }
481 }
482 for (int i = 0; i < model.page_word_size(); ++i) {
483 if (model.page_word(i) < 0 || model.page_word(i) > kMaxIndex) {
484 return false;
485 }
486 }
487 return true;
488 }
462 } // namespace safe_browsing 489 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698