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

Side by Side Diff: net/disk_cache/backend_unittest.cc

Issue 1725363005: Fix use after free in memory only backend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shorter2
Patch Set: coding style Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | net/disk_cache/memory/mem_entry_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 2929 matching lines...) Expand 10 before | Expand all | Expand 10 after
2940 } 2940 }
2941 2941
2942 TEST_F(DiskCacheBackendTest, MemoryOnlyBackendEviction) { 2942 TEST_F(DiskCacheBackendTest, MemoryOnlyBackendEviction) {
2943 SetMemoryOnlyMode(); 2943 SetMemoryOnlyMode();
2944 BackendEviction(); 2944 BackendEviction();
2945 } 2945 }
2946 2946
2947 // TODO(gavinp): Enable BackendEviction test for simple cache after performance 2947 // TODO(gavinp): Enable BackendEviction test for simple cache after performance
2948 // problems are addressed. See crbug.com/588184 for more information. 2948 // problems are addressed. See crbug.com/588184 for more information.
2949 2949
2950 // This overly specific looking test is a regression test aimed at
2951 // crbug.com/589186.
2952 TEST_F(DiskCacheBackendTest, MemoryCacheUseAfterFree) {
mmenke 2016/02/25 07:14:05 Should we run similar tests for disk cache impleme
gavinp 2016/02/25 15:55:32 Acknowledged.
2953 SetMemoryOnlyMode();
2954
2955 const int kMaxSize = 200 * 1024;
2956 const int kMaxEntryCount = 20;
2957 const int kWriteSize = kMaxSize / kMaxEntryCount;
2958
2959 SetMaxSize(kMaxSize);
2960 InitCache();
2961
2962 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kWriteSize));
2963 CacheTestFillBuffer(buffer->data(), kWriteSize, false);
2964
2965 // Create an entry to be our sparse entry that gets written later.
2966 disk_cache::Entry* entry;
2967 ASSERT_EQ(net::OK, CreateEntry("first parent", &entry));
2968 disk_cache::ScopedEntryPtr first_parent(entry);
2969 EXPECT_EQ(1024, first_parent->WriteSparseData(0, buffer.get(), 1024,
mmenke 2016/02/25 07:14:06 Should have a comment about why this first write i
gavinp 2016/02/25 15:55:32 Actually, it's not needed, so it's removed.
2970 net::CompletionCallback()));
2971
2972 // Create a ton of entries, and keep them open, to put the cache well above
2973 // its eviction threshhold.
2974 const int kTooManyEntriesCount = kMaxEntryCount * 2;
2975 disk_cache::ScopedEntryPtr open_entries[kTooManyEntriesCount];
mmenke 2016/02/25 07:14:06 optional: I'd suggest just using a std::vector<di
gavinp 2016/02/25 15:55:32 Done.
2976 std::string key_prefix("prefix");
2977 for (int i = 0; i < kTooManyEntriesCount; ++i) {
2978 ASSERT_EQ(net::OK, CreateEntry(key_prefix + base::IntToString(i), &entry));
2979 EXPECT_EQ(kWriteSize,
2980 WriteData(entry, 1, 0, buffer.get(), kWriteSize, false));
2981 open_entries[i].reset(entry);
2982 }
2983 EXPECT_LT(kMaxSize, CalculateSizeOfAllEntries());
2984
2985 // Writing this sparse data should not crash.
2986 EXPECT_EQ(1024, first_parent->WriteSparseData(32768, buffer.get(), 1024,
2987 net::CompletionCallback()));
2988 }
2989
2950 TEST_F(DiskCacheTest, Backend_UsageStatsTimer) { 2990 TEST_F(DiskCacheTest, Backend_UsageStatsTimer) {
2951 MessageLoopHelper helper; 2991 MessageLoopHelper helper;
2952 2992
2953 ASSERT_TRUE(CleanupCacheDir()); 2993 ASSERT_TRUE(CleanupCacheDir());
2954 scoped_ptr<disk_cache::BackendImpl> cache; 2994 scoped_ptr<disk_cache::BackendImpl> cache;
2955 cache.reset(new disk_cache::BackendImpl( 2995 cache.reset(new disk_cache::BackendImpl(
2956 cache_path_, base::ThreadTaskRunnerHandle::Get(), NULL)); 2996 cache_path_, base::ThreadTaskRunnerHandle::Get(), NULL));
2957 ASSERT_TRUE(NULL != cache.get()); 2997 ASSERT_TRUE(NULL != cache.get());
2958 cache->SetUnitTestMode(); 2998 cache->SetUnitTestMode();
2959 ASSERT_EQ(net::OK, cache->SyncInit()); 2999 ASSERT_EQ(net::OK, cache->SyncInit());
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
3703 // after closing. 3743 // after closing.
3704 // NOTE: IF THIS TEST IS FLAKY THEN IT IS FAILING. See https://crbug.com/416940 3744 // NOTE: IF THIS TEST IS FLAKY THEN IT IS FAILING. See https://crbug.com/416940
3705 TEST_F(DiskCacheBackendTest, SimpleCacheDeleteQuickly) { 3745 TEST_F(DiskCacheBackendTest, SimpleCacheDeleteQuickly) {
3706 SetSimpleCacheMode(); 3746 SetSimpleCacheMode();
3707 for (int i = 0; i < 100; ++i) { 3747 for (int i = 0; i < 100; ++i) {
3708 InitCache(); 3748 InitCache();
3709 cache_.reset(); 3749 cache_.reset();
3710 EXPECT_TRUE(CleanupCacheDir()); 3750 EXPECT_TRUE(CleanupCacheDir());
3711 } 3751 }
3712 } 3752 }
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/memory/mem_entry_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698