Skip to content

Commit

Permalink
Content verification: Don't fail on non-existence.
Browse files Browse the repository at this point in the history
This prevents content verification (when active) from disabling
an extension when the extension attempts to load a non-existent
resource in its own chrome-extension URL space.

BUG=404802

Review URL: https://codereview.chromium.org/512573003

Cr-Commit-Position: refs/heads/master@{#292095}
  • Loading branch information
krockot authored and Commit bot committed Aug 27, 2014
1 parent be8f40e commit 88d96e6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 8 additions & 0 deletions extensions/browser/content_hash_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ContentHashReader::ContentHashReader(const std::string& extension_id,
relative_path_(relative_path),
key_(key),
status_(NOT_INITIALIZED),
content_exists_(false),
have_verified_contents_(false),
have_computed_hashes_(false),
block_size_(0) {
Expand All @@ -50,6 +51,13 @@ bool ContentHashReader::Init() {
base::FilePath verified_contents_path =
file_util::GetVerifiedContentsPath(extension_root_);

// Check that this is a valid resource to verify (i.e., it exists).
base::FilePath content_path = extension_root_.Append(relative_path_);
if (!base::PathExists(content_path))
return false;

content_exists_ = true;

if (!base::PathExists(verified_contents_path))
return false;

Expand Down
10 changes: 8 additions & 2 deletions extensions/browser/content_hash_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ class ContentHashReader : public base::RefCountedThreadSafe<ContentHashReader> {
// should likely be discarded.
bool Init();

// Indicates whether the content in question exists in the local extension
// installation. This may be |false| if Init fails.
bool content_exists() const { return content_exists_; }

// These return whether we found valid verified_contents.json /
// computed_hashes.json files respectively. Note that both of these can be
// true but we still didn't find an entry for |relative_path_| in them.
bool have_verified_contents() { return have_verified_contents_; }
bool have_computed_hashes() { return have_computed_hashes_; }
bool have_verified_contents() const { return have_verified_contents_; }
bool have_computed_hashes() const { return have_computed_hashes_; }

// Return the number of blocks and block size, respectively. Only valid after
// calling Init().
Expand All @@ -69,6 +73,8 @@ class ContentHashReader : public base::RefCountedThreadSafe<ContentHashReader> {

InitStatus status_;

bool content_exists_;

bool have_verified_contents_;
bool have_computed_hashes_;

Expand Down
10 changes: 7 additions & 3 deletions extensions/browser/content_verify_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ bool ContentVerifyJob::FinishBlock() {

void ContentVerifyJob::OnHashesReady(bool success) {
if (!success && !g_test_delegate) {
if (hash_reader_->have_verified_contents() &&
hash_reader_->have_computed_hashes())
if (!hash_reader_->content_exists()) {
// Ignore verification of non-existent resources.
return;
} else if (hash_reader_->have_verified_contents() &&
hash_reader_->have_computed_hashes()) {
DispatchFailureCallback(NO_HASHES_FOR_FILE);
else
} else {
DispatchFailureCallback(MISSING_ALL_HASHES);
}
return;
}

Expand Down

0 comments on commit 88d96e6

Please sign in to comment.