diff options
author | rvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-16 01:19:19 +0000 |
---|---|---|
committer | rvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-16 01:19:19 +0000 |
commit | 52c7571772423908a3c672a55885c1595a45c4ae (patch) | |
tree | bcd08b180bf163379d67be9b7fcf06d6bacfda96 /net | |
parent | e04b0dc9ab239409cd01856be93553308bd6bb26 (diff) | |
download | chromium_src-52c7571772423908a3c672a55885c1595a45c4ae.zip chromium_src-52c7571772423908a3c672a55885c1595a45c4ae.tar.gz chromium_src-52c7571772423908a3c672a55885c1595a45c4ae.tar.bz2 |
Disk Cache: Discard entries from ReadData if something is clearly wrong.
BUG=107457
TEST=net_unittests
Review URL: http://codereview.chromium.org/8913013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114740 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/disk_cache/entry_impl.cc | 9 | ||||
-rw-r--r-- | net/disk_cache/entry_unittest.cc | 31 |
2 files changed, 38 insertions, 2 deletions
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc index 7e13029..b0226a7 100644 --- a/net/disk_cache/entry_impl.cc +++ b/net/disk_cache/entry_impl.cc @@ -974,12 +974,16 @@ int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf, address.set_value(entry_.Data()->data_addr[index]); DCHECK(address.is_initialized()); - if (!address.is_initialized()) + if (!address.is_initialized()) { + DoomImpl(); return net::ERR_FAILED; + } File* file = GetBackingFile(address, index); - if (!file) + if (!file) { + DoomImpl(); return net::ERR_FAILED; + } size_t file_offset = offset; if (address.is_block_file()) { @@ -1000,6 +1004,7 @@ int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf, if (!file->Read(buf->data(), buf_len, file_offset, io_callback, &completed)) { if (io_callback) io_callback->Discard(); + DoomImpl(); return net::ERR_FAILED; } diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc index a763dbb..c537ef1 100644 --- a/net/disk_cache/entry_unittest.cc +++ b/net/disk_cache/entry_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/basictypes.h" +#include "base/file_util.h" #include "base/threading/platform_thread.h" #include "base/timer.h" #include "base/string_util.h" @@ -1244,6 +1245,36 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) { DoomedEntry(); } +// Tests that we discard entries if the data is missing. +TEST_F(DiskCacheEntryTest, MissingData) { + SetDirectMode(); + InitCache(); + + std::string key("the first key"); + disk_cache::Entry* entry; + ASSERT_EQ(net::OK, CreateEntry(key, &entry)); + + // Write to an external file. + const int kSize = 20000; + scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); + CacheTestFillBuffer(buffer->data(), kSize, false); + EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer, kSize, false)); + entry->Close(); + FlushQueueForTest(); + + disk_cache::Addr address(0x80000001); + FilePath name = cache_impl_->GetFileName(address); + EXPECT_TRUE(file_util::Delete(name, false)); + + // Attempt to read the data. + ASSERT_EQ(net::OK, OpenEntry(key, &entry)); + EXPECT_EQ(net::ERR_FAILED, ReadData(entry, 0, 0, buffer, kSize)); + entry->Close(); + + // The entry should be gone. + ASSERT_NE(net::OK, OpenEntry(key, &entry)); +} + // Test that child entries in a memory cache backend are not visible from // enumerations. TEST_F(DiskCacheEntryTest, MemoryOnlyEnumerationWithSparseEntries) { |