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

Side by Side Diff: net/disk_cache/simple/simple_test_util.cc

Issue 2205073002: Simple Cache: validate lengths before allocations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 4 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 | « net/disk_cache/simple/simple_test_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "net/disk_cache/simple/simple_test_util.h" 5 #include "net/disk_cache/simple/simple_test_util.h"
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "net/base/hash_value.h" 9 #include "net/base/hash_value.h"
10 #include "net/disk_cache/simple/simple_entry_format.h" 10 #include "net/disk_cache/simple/simple_entry_format.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 static_assert(sizeof(corrupt_data) <= sizeof(net::SHA256HashValue), 90 static_assert(sizeof(corrupt_data) <= sizeof(net::SHA256HashValue),
91 "corrupt data should not be larger than a SHA-256"); 91 "corrupt data should not be larger than a SHA-256");
92 if (entry_file.Write( 92 if (entry_file.Write(
93 file_length - sizeof(eof_record) - sizeof(net::SHA256HashValue), 93 file_length - sizeof(eof_record) - sizeof(net::SHA256HashValue),
94 corrupt_data, sizeof(corrupt_data)) != sizeof(corrupt_data)) { 94 corrupt_data, sizeof(corrupt_data)) != sizeof(corrupt_data)) {
95 return false; 95 return false;
96 } 96 }
97 return true; 97 return true;
98 } 98 }
99 99
100 bool CorruptStream0LengthFromEntry(const std::string& key,
101 const base::FilePath& cache_path) {
102 FilePath entry_file_path = cache_path.AppendASCII(
103 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
104 int flags = File::FLAG_OPEN | File::FLAG_READ | File::FLAG_WRITE;
105 File entry_file(entry_file_path, flags);
106 if (!entry_file.IsValid())
107 return false;
108 int file_length = entry_file.GetLength();
109 SimpleFileEOF eof_record;
110 if (entry_file.Read(file_length - sizeof(eof_record),
111 reinterpret_cast<char*>(&eof_record),
112 sizeof(eof_record)) != sizeof(eof_record)) {
113 return false;
114 }
115 if (eof_record.final_magic_number != disk_cache::kSimpleFinalMagicNumber)
116 return false;
117
118 // Set the stream size to a clearly invalidly large value.
119 eof_record.stream_size = std::numeric_limits<uint32_t>::max() - 50;
120 if (entry_file.Write(file_length - sizeof(eof_record),
121 reinterpret_cast<char*>(&eof_record),
122 sizeof(eof_record)) != sizeof(eof_record)) {
123 return false;
124 }
125 return true;
126 }
127
100 } // namespace simple_util 128 } // namespace simple_util
101 } // namespace disk_cache 129 } // namespace disk_cache
OLDNEW
« 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