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

Unified Diff: net/http/mock_http_cache.cc

Issue 2089783002: [net/cache] Avoid the cache for responses exceeding 2GB. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build for configurations where DCHECK is disabled. Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_transaction_test_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/mock_http_cache.cc
diff --git a/net/http/mock_http_cache.cc b/net/http/mock_http_cache.cc
index 682aff529ada0053bdc0e46d7fea8e7c0f18d40e..560ae9c80daa5217f405550c9a08fb8b1ad2fbde 100644
--- a/net/http/mock_http_cache.cc
+++ b/net/http/mock_http_cache.cc
@@ -20,6 +20,14 @@ namespace net {
namespace {
+// During testing, we are going to limit the size of a cache entry to this many
+// bytes using DCHECKs in order to prevent a test from causing unbounded memory
+// growth. In practice cache entry shouldn't come anywhere near this limit for
+// tests that use the mock cache. If they do, that's likely a problem with the
+// test. If a test requires using massive cache entries, they should use a real
+// cache backend instead.
+const int kMaxMockCacheEntrySize = 100 * 1000 * 1000;
+
// We can override the test mode for a given operation by setting this global
// variable.
int g_test_mode = 0;
@@ -139,6 +147,7 @@ int MockDiskEntry::WriteData(int index,
if (offset < 0 || offset > static_cast<int>(data_[index].size()))
return ERR_FAILED;
+ DCHECK_LT(offset + buf_len, kMaxMockCacheEntrySize);
data_[index].resize(offset + buf_len);
if (buf_len)
memcpy(&data_[index][offset], buf->data(), buf_len);
@@ -208,8 +217,10 @@ int MockDiskEntry::WriteSparseData(int64_t offset,
DCHECK(offset < std::numeric_limits<int32_t>::max());
int real_offset = static_cast<int>(offset);
- if (static_cast<int>(data_[1].size()) < real_offset + buf_len)
+ if (static_cast<int>(data_[1].size()) < real_offset + buf_len) {
+ DCHECK_LT(real_offset + buf_len, kMaxMockCacheEntrySize);
data_[1].resize(real_offset + buf_len);
+ }
memcpy(&data_[1][real_offset], buf->data(), buf_len);
if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_WRITE)
« no previous file with comments | « net/http/http_transaction_test_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698