summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-28 22:54:28 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-28 22:54:28 +0000
commit705dce1aeb30a7aa569c047b13fb3dd2772f459b (patch)
tree9ce08e7415bc77b4c0209526c4432b6933783c0c /net/disk_cache
parent534c66c7338db94220b0f5995b299415d99e918e (diff)
downloadchromium_src-705dce1aeb30a7aa569c047b13fb3dd2772f459b.zip
chromium_src-705dce1aeb30a7aa569c047b13fb3dd2772f459b.tar.gz
chromium_src-705dce1aeb30a7aa569c047b13fb3dd2772f459b.tar.bz2
Disk cache: Make sure that we don't access the index file
if it was truncated. BUG=41563 TEST=unittest Review URL: http://codereview.chromium.org/1719024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45878 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/backend_impl.cc8
-rw-r--r--net/disk_cache/backend_unittest.cc15
-rw-r--r--net/disk_cache/trace.cc5
3 files changed, 26 insertions, 2 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 98b8804a..c094472 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -1080,6 +1080,14 @@ bool BackendImpl::InitBackingStore(bool* file_created) {
LOG(ERROR) << "Unable to map Index file";
return false;
}
+
+ if (index_->GetLength() < sizeof(Index)) {
+ // We verify this again on CheckIndex() but it's easier to make sure now
+ // that the header is there.
+ LOG(ERROR) << "Corrupt Index file";
+ return false;
+ }
+
return true;
}
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index abc2c08..2c019b5 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -241,6 +241,21 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO) {
MessageLoop::current()->RunAllPending();
}
+#if defined(OS_WIN) || defined(OS_MACOSX)
+// This test fails on linux. TODO(rvargas): Find out why (bug 41563).
+TEST_F(DiskCacheTest, TruncatedIndex) {
+ FilePath path = GetCacheFilePath();
+ ASSERT_TRUE(DeleteCache(path));
+ FilePath index = path.AppendASCII("Index");
+ ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5));
+ scoped_ptr<disk_cache::Backend> backend;
+ backend.reset(disk_cache::BackendImpl::CreateBackend(path, false, 0,
+ net::DISK_CACHE,
+ disk_cache::kNone));
+ ASSERT_TRUE(backend.get() == NULL);
+}
+#endif
+
void DiskCacheBackendTest::BackendSetSize() {
SetDirectMode();
const int cache_size = 0x10000; // 64 kB
diff --git a/net/disk_cache/trace.cc b/net/disk_cache/trace.cc
index 94d9fad..7a61e20 100644
--- a/net/disk_cache/trace.cc
+++ b/net/disk_cache/trace.cc
@@ -70,14 +70,15 @@ void InitTrace(void) {
}
void DestroyTrace(void) {
- DCHECK(s_trace_buffer);
delete s_trace_buffer;
s_trace_buffer = NULL;
s_trace_object = NULL;
}
void Trace(const char* format, ...) {
- DCHECK(s_trace_buffer);
+ if (!s_trace_buffer)
+ return;
+
va_list ap;
va_start(ap, format);