diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-15 18:22:55 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-15 18:22:55 +0000 |
commit | 1fb6cb3711616c2478deb91e1ae3b6264f148fb4 (patch) | |
tree | d05f4739f0b5bbcb828cd1c47df4eac26627141e /chrome/browser/safe_browsing | |
parent | 3bdb22ba41f71b7cff189f0f0b295a0b2fa4db1a (diff) | |
download | chromium_src-1fb6cb3711616c2478deb91e1ae3b6264f148fb4.zip chromium_src-1fb6cb3711616c2478deb91e1ae3b6264f148fb4.tar.gz chromium_src-1fb6cb3711616c2478deb91e1ae3b6264f148fb4.tar.bz2 |
Change SB file store to use new base/md5.h interface.
r260731 landed a version of the function into base/ so that this code didn't
need to have such an implementation dependency.
Add a v8 golden-file test to make certain that the resulting digest calculation
matches. FileStoreVersion8 was generated pre-change.
BUG=none
R=mattm@chromium.org
Review URL: https://codereview.chromium.org/236743004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263932 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing')
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_store_file.cc | 12 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc | 79 |
2 files changed, 81 insertions, 10 deletions
diff --git a/chrome/browser/safe_browsing/safe_browsing_store_file.cc b/chrome/browser/safe_browsing/safe_browsing_store_file.cc index 50c1b5f..e89d412 100644 --- a/chrome/browser/safe_browsing/safe_browsing_store_file.cc +++ b/chrome/browser/safe_browsing/safe_browsing_store_file.cc @@ -212,17 +212,9 @@ void DeleteChunksFromSet(const base::hash_set<int32>& deleted, } } -// base::MD5Final() modifies |context| in generating |digest|. This wrapper -// generates an intermediate digest without modifying the context. -void MD5IntermediateDigest(base::MD5Digest* digest, base::MD5Context* context) { - base::MD5Context temp_context; - memcpy(&temp_context, context, sizeof(temp_context)); - base::MD5Final(digest, &temp_context); -} - bool ReadAndVerifyChecksum(FILE* fp, base::MD5Context* context) { base::MD5Digest calculated_digest; - MD5IntermediateDigest(&calculated_digest, context); + base::MD5IntermediateFinal(&calculated_digest, context); base::MD5Digest file_digest; if (!ReadItem(&file_digest, fp, context)) @@ -352,7 +344,7 @@ bool WriteHeader(uint32 out_stride, // Write out the header digest. base::MD5Digest header_digest; - MD5IntermediateDigest(&header_digest, context); + base::MD5IntermediateFinal(&header_digest, context); if (!WriteItem(header_digest, fp, context)) return false; diff --git a/chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc index e56b974..e17f7e18 100644 --- a/chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc +++ b/chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc @@ -840,4 +840,83 @@ TEST_F(SafeBrowsingStoreFileTest, Version7) { } #endif +// Test that a golden v8 file can be read by the current code. All platforms +// generating v8 files are little-endian, so there is no point to testing this +// transition if/when a big-endian port is added. +#if defined(ARCH_CPU_LITTLE_ENDIAN) +TEST_F(SafeBrowsingStoreFileTest, Version8) { + store_.reset(); + + // Copy the golden file into temporary storage. The golden file contains: + // - Add chunk kAddChunk1 containing kHash1.prefix and kHash2. + // - Sub chunk kSubChunk1 containing kHash3. + const char kBasename[] = "FileStoreVersion8"; + base::FilePath golden_path; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &golden_path)); + golden_path = golden_path.AppendASCII("SafeBrowsing"); + golden_path = golden_path.AppendASCII(kBasename); + ASSERT_TRUE(base::CopyFile(golden_path, filename_)); + + // Reset the store to make sure it re-reads the file. + store_.reset(new SafeBrowsingStoreFile()); + store_->Init(filename_, + base::Bind(&SafeBrowsingStoreFileTest::OnCorruptionDetected, + base::Unretained(this))); + + // Check that the expected prefixes and hashes are in place. + SBAddPrefixes add_prefixes; + EXPECT_TRUE(store_->GetAddPrefixes(&add_prefixes)); + ASSERT_EQ(2U, add_prefixes.size()); + EXPECT_EQ(kAddChunk1, add_prefixes[0].chunk_id); + EXPECT_EQ(kHash1.prefix, add_prefixes[0].prefix); + EXPECT_EQ(kAddChunk1, add_prefixes[1].chunk_id); + EXPECT_EQ(kHash2.prefix, add_prefixes[1].prefix); + + std::vector<SBAddFullHash> add_hashes; + EXPECT_TRUE(store_->GetAddFullHashes(&add_hashes)); + ASSERT_EQ(1U, add_hashes.size()); + EXPECT_EQ(kAddChunk1, add_hashes[0].chunk_id); + EXPECT_TRUE(SBFullHashEqual(kHash2, add_hashes[0].full_hash)); + + // Attempt an update to make sure things work end-to-end. + EXPECT_TRUE(store_->BeginUpdate()); + + // Still has the chunks expected in the next update. + std::vector<int> chunks; + store_->GetAddChunks(&chunks); + ASSERT_EQ(1U, chunks.size()); + EXPECT_EQ(kAddChunk1, chunks[0]); + + store_->GetSubChunks(&chunks); + ASSERT_EQ(1U, chunks.size()); + EXPECT_EQ(kSubChunk1, chunks[0]); + + EXPECT_TRUE(store_->CheckAddChunk(kAddChunk1)); + EXPECT_TRUE(store_->CheckSubChunk(kSubChunk1)); + + // Sub chunk kAddChunk1 hash kHash2. + store_->SetSubChunk(kSubChunk2); + EXPECT_TRUE(store_->CheckSubChunk(kSubChunk1)); + EXPECT_TRUE(store_->WriteSubPrefix(kSubChunk1, kAddChunk1, kHash2.prefix)); + EXPECT_TRUE(store_->WriteSubHash(kSubChunk1, kAddChunk1, kHash2)); + EXPECT_TRUE(store_->FinishChunk()); + + { + std::vector<SBAddFullHash> pending_adds; + safe_browsing::PrefixSetBuilder builder; + std::vector<SBAddFullHash> add_full_hashes_result; + EXPECT_TRUE(store_->FinishUpdate(pending_adds, + &builder, + &add_full_hashes_result)); + + // The sub'ed prefix and hash are gone. + std::vector<SBPrefix> prefixes_result; + builder.GetPrefixSet()->GetPrefixes(&prefixes_result); + ASSERT_EQ(1U, prefixes_result.size()); + EXPECT_EQ(kHash1.prefix, prefixes_result[0]); + EXPECT_TRUE(add_full_hashes_result.empty()); + } +} +#endif + } // namespace |