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

Side by Side 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 unified diff | Download patch
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/prefix_set.h" 5 #include "chrome/browser/safe_browsing/prefix_set.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <math.h> 8 #include <math.h>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 SBPrefix current = index_[ii].first; 159 SBPrefix current = index_[ii].first;
160 prefixes->push_back(current); 160 prefixes->push_back(current);
161 for (size_t di = index_[ii].second; di < deltas_end; ++di) { 161 for (size_t di = index_[ii].second; di < deltas_end; ++di) {
162 current += deltas_[di]; 162 current += deltas_[di];
163 prefixes->push_back(current); 163 prefixes->push_back(current);
164 } 164 }
165 } 165 }
166 } 166 }
167 167
168 // NOTE(shess): For debugging potential memory corruption. I wanted
169 // to test that the output of GetPrefixes() matched the checksum over
170 // the unique elements in the input to the constructor, but the buffer
171 // for GetPrefixes() to write to could itself be corrupted. That
172 // would make it look like GetPrefixes() itself was broken. At that
173 // point my head exploded, so I wrote this.
174 SBPrefix PrefixSet::GetPrefixesChecksum() const {
175 SBPrefix checksum = 0;
176
177 for (size_t ii = 0; ii < index_.size(); ++ii) {
178 // The deltas for this |index_| entry run to the next index entry,
179 // or the end of the deltas.
180 const size_t deltas_end =
181 (ii + 1 < index_.size()) ? index_[ii + 1].second : deltas_.size();
182
183 SBPrefix current = index_[ii].first;
184 checksum ^= current;
185 for (size_t di = index_[ii].second; di < deltas_end; ++di) {
186 current += deltas_[di];
187 checksum ^= current;
188 }
189 }
190
191 return checksum;
192 }
193
168 // static 194 // static
169 PrefixSet* PrefixSet::LoadFile(const FilePath& filter_name) { 195 PrefixSet* PrefixSet::LoadFile(const FilePath& filter_name) {
170 int64 size_64; 196 int64 size_64;
171 if (!file_util::GetFileSize(filter_name, &size_64)) 197 if (!file_util::GetFileSize(filter_name, &size_64))
172 return NULL; 198 return NULL;
173 using base::MD5Digest; 199 using base::MD5Digest;
174 if (size_64 < static_cast<int64>(sizeof(FileHeader) + sizeof(MD5Digest))) 200 if (size_64 < static_cast<int64>(sizeof(FileHeader) + sizeof(MD5Digest)))
175 return NULL; 201 return NULL;
176 202
177 file_util::ScopedFILE file(file_util::OpenFile(filter_name, "rb")); 203 file_util::ScopedFILE file(file_util::OpenFile(filter_name, "rb"));
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } 386 }
361 387
362 for (size_t di = 0; di < deltas_.size(); ++di) { 388 for (size_t di = 0; di < deltas_.size(); ++di) {
363 checksum ^= static_cast<uint32>(deltas_[di]); 389 checksum ^= static_cast<uint32>(deltas_[di]);
364 } 390 }
365 391
366 return checksum == checksum_; 392 return checksum == checksum_;
367 } 393 }
368 394
369 } // namespace safe_browsing 395 } // namespace safe_browsing
OLDNEW
« 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