Chromium Code Reviews| 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..16f0b32750dee9adf24bcc2770a5796da38b99d9 100644 |
| --- a/net/http/mock_http_cache.cc |
| +++ b/net/http/mock_http_cache.cc |
| @@ -20,6 +20,16 @@ namespace net { |
| namespace { |
| +#if DCHECK_IS_ON() |
| +// 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 = 100000000; |
|
gavinp
2016/06/28 14:24:43
Nit: I have trouble counting zeroes this quickly.
asanka
2016/06/28 16:55:38
Done. :-)
|
| +#endif |
| + |
| // We can override the test mode for a given operation by setting this global |
| // variable. |
| int g_test_mode = 0; |
| @@ -139,6 +149,7 @@ int MockDiskEntry::WriteData(int index, |
| if (offset < 0 || offset > static_cast<int>(data_[index].size())) |
| return ERR_FAILED; |
| + DCHECK(offset + buf_len < kMaxMockCacheEntrySize); |
|
gavinp
2016/06/28 14:24:43
DCHECK_LT?
asanka
2016/06/28 16:55:38
Done here and on L223.
|
| data_[index].resize(offset + buf_len); |
| if (buf_len) |
| memcpy(&data_[index][offset], buf->data(), buf_len); |
| @@ -208,8 +219,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(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) |