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

Unified Diff: net/disk_cache/simple/simple_test_util.cc

Issue 2086053003: Simple Cache: validate lengths before allocations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remediate Created 4 years, 5 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/disk_cache/simple/simple_test_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/simple/simple_test_util.cc
diff --git a/net/disk_cache/simple/simple_test_util.cc b/net/disk_cache/simple/simple_test_util.cc
index 97982ff10b8d540407c4edd061e0e49c1dcdc667..9463b63eab4ce6a9e61986adb1fbacec6e036d4d 100644
--- a/net/disk_cache/simple/simple_test_util.cc
+++ b/net/disk_cache/simple/simple_test_util.cc
@@ -97,5 +97,33 @@ bool CorruptKeySHA256FromEntry(const std::string& key,
return true;
}
+bool CorruptStream0LengthFromEntry(const std::string& key,
+ const base::FilePath& cache_path) {
+ FilePath entry_file_path = cache_path.AppendASCII(
+ disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
+ int flags = File::FLAG_OPEN | File::FLAG_READ | File::FLAG_WRITE;
+ File entry_file(entry_file_path, flags);
+ if (!entry_file.IsValid())
+ return false;
+ int file_length = entry_file.GetLength();
+ SimpleFileEOF eof_record;
+ if (entry_file.Read(file_length - sizeof(eof_record),
+ reinterpret_cast<char*>(&eof_record),
+ sizeof(eof_record)) != sizeof(eof_record)) {
+ return false;
+ }
+ if (eof_record.final_magic_number != disk_cache::kSimpleFinalMagicNumber)
+ return false;
+
+ // Set the stream size to a clearly invalidly large value.
+ eof_record.stream_size = std::numeric_limits<uint32_t>::max() - 50;
+ if (entry_file.Write(file_length - sizeof(eof_record),
+ reinterpret_cast<char*>(&eof_record),
+ sizeof(eof_record)) != sizeof(eof_record)) {
+ return false;
+ }
+ return true;
+}
+
} // namespace simple_util
} // namespace disk_cache
« no previous file with comments | « net/disk_cache/simple/simple_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698