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

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

Issue 10834045: Instrument to catch corruption constructing safe-browsing filters. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 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
« no previous file with comments | « chrome/browser/safe_browsing/prefix_set.h ('k') | chrome/browser/safe_browsing/safe_browsing_database.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 d9a889745c43a2c82bf4a27daaf7b3c75aa89072..4191427e43667b41026ea05ce9e80e4694d3167c 100644
--- a/chrome/browser/safe_browsing/prefix_set.cc
+++ b/chrome/browser/safe_browsing/prefix_set.cc
@@ -165,6 +165,32 @@ void PrefixSet::GetPrefixes(std::vector<SBPrefix>* prefixes) const {
}
}
+// NOTE(shess): For debugging potential memory corruption. I wanted
+// to test that the output of GetPrefixes() matched the checksum over
+// the unique elements in the input to the constructor, but the buffer
+// for GetPrefixes() to write to could itself be corrupted. That
+// would make it look like GetPrefixes() itself was broken. At that
+// point my head exploded, so I wrote this.
+SBPrefix PrefixSet::GetPrefixesChecksum() const {
+ SBPrefix checksum = 0;
+
+ for (size_t ii = 0; ii < index_.size(); ++ii) {
+ // The deltas for this |index_| entry run to the next index entry,
+ // or the end of the deltas.
+ const size_t deltas_end =
+ (ii + 1 < index_.size()) ? index_[ii + 1].second : deltas_.size();
+
+ SBPrefix current = index_[ii].first;
+ checksum ^= current;
+ for (size_t di = index_[ii].second; di < deltas_end; ++di) {
+ current += deltas_[di];
+ checksum ^= current;
+ }
+ }
+
+ return checksum;
+}
+
// static
PrefixSet* PrefixSet::LoadFile(const FilePath& filter_name) {
int64 size_64;
« no previous file with comments | « chrome/browser/safe_browsing/prefix_set.h ('k') | chrome/browser/safe_browsing/safe_browsing_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698