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

Unified Diff: extensions/browser/content_hash_fetcher.cc

Issue 436563004: Fix for 0-length file problem in content verification (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes from review comments Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/computed_hashes_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/content_hash_fetcher.cc
diff --git a/extensions/browser/content_hash_fetcher.cc b/extensions/browser/content_hash_fetcher.cc
index 68b0c92f9fb556e2b827b93fbfdb5b750b21525f..421271125eb7b51ed275bdd8752085e6760da7ae 100644
--- a/extensions/browser/content_hash_fetcher.cc
+++ b/extensions/browser/content_hash_fetcher.cc
@@ -12,14 +12,12 @@
#include "base/json/json_reader.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram.h"
-#include "base/stl_util.h"
#include "base/synchronization/lock.h"
#include "base/task_runner_util.h"
#include "base/timer/elapsed_timer.h"
#include "base/version.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
-#include "crypto/secure_hash.h"
#include "crypto/sha2.h"
#include "extensions/browser/computed_hashes.h"
#include "extensions/browser/content_hash_tree.h"
@@ -367,26 +365,7 @@ bool ContentHashFetcherJob::CreateHashes(const base::FilePath& hashes_file) {
// Iterate through taking the hash of each block of size (block_size_) of
// the file.
std::vector<std::string> hashes;
- size_t offset = 0;
- while (offset < contents.size()) {
- if (IsCancelled())
- return false;
- const char* block_start = contents.data() + offset;
- size_t bytes_to_read =
- std::min(contents.size() - offset, static_cast<size_t>(block_size_));
- DCHECK(bytes_to_read > 0);
- scoped_ptr<crypto::SecureHash> hash(
- crypto::SecureHash::Create(crypto::SecureHash::SHA256));
- hash->Update(block_start, bytes_to_read);
-
- hashes.push_back(std::string());
- std::string* buffer = &hashes.back();
- buffer->resize(crypto::kSHA256Length);
- hash->Finish(string_as_array(buffer), buffer->size());
-
- // Get ready for next iteration.
- offset += bytes_to_read;
- }
+ ComputedHashes::ComputeHashesForContent(contents, block_size_, &hashes);
std::string root =
ComputeTreeHashRoot(hashes, block_size_ / crypto::kSHA256Length);
if (expected_root && *expected_root != root) {
« no previous file with comments | « extensions/browser/computed_hashes_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698