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

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

Issue 10896048: Transition safe browsing from bloom filter to prefix set. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix prefix set read/write for empty/sparse sets. Created 8 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/prefix_set_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/safe_browsing/prefix_set.cc
diff --git a/chrome/browser/safe_browsing/prefix_set.cc b/chrome/browser/safe_browsing/prefix_set.cc
index 8af034d5f66f7ec573b783ffd5f46c17d0616484..c55c9ab7224a1c670736113101ecf29bdd5c50bf 100644
--- a/chrome/browser/safe_browsing/prefix_set.cc
+++ b/chrome/browser/safe_browsing/prefix_set.cc
@@ -193,22 +193,26 @@ PrefixSet* PrefixSet::LoadFile(const FilePath& filter_name) {
// Read the index vector. Herb Sutter indicates that vectors are
// guaranteed to be contiuguous, so reading to where element 0 lives
// is valid.
- index.resize(header.index_size);
- read = fread(&(index[0]), sizeof(index[0]), index.size(), file.get());
- if (read != index.size())
- return NULL;
- base::MD5Update(&context,
- base::StringPiece(reinterpret_cast<char*>(&(index[0])),
- index_bytes));
+ if (header.index_size) {
+ index.resize(header.index_size);
+ read = fread(&(index[0]), sizeof(index[0]), index.size(), file.get());
+ if (read != index.size())
+ return NULL;
+ base::MD5Update(&context,
+ base::StringPiece(reinterpret_cast<char*>(&(index[0])),
+ index_bytes));
+ }
// Read vector of deltas.
- deltas.resize(header.deltas_size);
- read = fread(&(deltas[0]), sizeof(deltas[0]), deltas.size(), file.get());
- if (read != deltas.size())
- return NULL;
- base::MD5Update(&context,
- base::StringPiece(reinterpret_cast<char*>(&(deltas[0])),
- deltas_bytes));
+ if (header.deltas_size) {
+ deltas.resize(header.deltas_size);
+ read = fread(&(deltas[0]), sizeof(deltas[0]), deltas.size(), file.get());
+ if (read != deltas.size())
+ return NULL;
+ base::MD5Update(&context,
+ base::StringPiece(reinterpret_cast<char*>(&(deltas[0])),
+ deltas_bytes));
+ }
base::MD5Digest calculated_digest;
base::MD5Final(&calculated_digest, &context);
@@ -256,23 +260,29 @@ bool PrefixSet::WriteFile(const FilePath& filter_name) const {
// As for reads, the standard guarantees the ability to access the
// contents of the vector by a pointer to an element.
- const size_t index_bytes = sizeof(index_[0]) * index_.size();
- written = fwrite(&(index_[0]), sizeof(index_[0]), index_.size(), file.get());
- if (written != index_.size())
- return false;
- base::MD5Update(&context,
- base::StringPiece(reinterpret_cast<const char*>(&(index_[0])),
- index_bytes));
-
- const size_t deltas_bytes = sizeof(deltas_[0]) * deltas_.size();
- written = fwrite(&(deltas_[0]), sizeof(deltas_[0]), deltas_.size(),
- file.get());
- if (written != deltas_.size())
- return false;
- base::MD5Update(&context,
- base::StringPiece(
- reinterpret_cast<const char*>(&(deltas_[0])),
- deltas_bytes));
+ if (index_.size()) {
+ const size_t index_bytes = sizeof(index_[0]) * index_.size();
+ written = fwrite(&(index_[0]), sizeof(index_[0]), index_.size(),
+ file.get());
+ if (written != index_.size())
+ return false;
+ base::MD5Update(&context,
+ base::StringPiece(
+ reinterpret_cast<const char*>(&(index_[0])),
+ index_bytes));
+ }
+
+ if (deltas_.size()) {
+ const size_t deltas_bytes = sizeof(deltas_[0]) * deltas_.size();
+ written = fwrite(&(deltas_[0]), sizeof(deltas_[0]), deltas_.size(),
+ file.get());
+ if (written != deltas_.size())
+ return false;
+ base::MD5Update(&context,
+ base::StringPiece(
+ reinterpret_cast<const char*>(&(deltas_[0])),
+ deltas_bytes));
+ }
base::MD5Digest digest;
base::MD5Final(&digest, &context);
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/prefix_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698