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

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

Issue 2404823002: Fix error handling in POSIX version of the base::File::GetLength. (Closed)
Patch Set: Fix error handling in POSIX version of the base::File::GetLength. Created 4 years 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/blockfile/file_posix.cc ('k') | sandbox/win/src/process_mitigations_test.cc » ('j') | 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 9463b63eab4ce6a9e61986adb1fbacec6e036d4d..0251f3ad9142a8023b9fe8465706cccd408a6c6e 100644
--- a/net/disk_cache/simple/simple_test_util.cc
+++ b/net/disk_cache/simple/simple_test_util.cc
@@ -37,8 +37,10 @@ bool RemoveKeySHA256FromEntry(const std::string& key,
File entry_file(entry_file_path, flags);
if (!entry_file.IsValid())
return false;
- int file_length = entry_file.GetLength();
+ int64_t file_length = entry_file.GetLength();
SimpleFileEOF eof_record;
+ if (file_length < static_cast<int64_t>(sizeof(eof_record)))
+ return false;
if (entry_file.Read(file_length - sizeof(eof_record),
reinterpret_cast<char*>(&eof_record),
sizeof(eof_record)) != sizeof(eof_record)) {
@@ -73,8 +75,10 @@ bool CorruptKeySHA256FromEntry(const std::string& key,
File entry_file(entry_file_path, flags);
if (!entry_file.IsValid())
return false;
- int file_length = entry_file.GetLength();
+ int64_t file_length = entry_file.GetLength();
SimpleFileEOF eof_record;
+ if (file_length < static_cast<int64_t>(sizeof(eof_record)))
+ return false;
if (entry_file.Read(file_length - sizeof(eof_record),
reinterpret_cast<char*>(&eof_record),
sizeof(eof_record)) != sizeof(eof_record)) {
@@ -105,8 +109,10 @@ bool CorruptStream0LengthFromEntry(const std::string& key,
File entry_file(entry_file_path, flags);
if (!entry_file.IsValid())
return false;
- int file_length = entry_file.GetLength();
+ int64_t file_length = entry_file.GetLength();
SimpleFileEOF eof_record;
+ if (file_length < static_cast<int64_t>(sizeof(eof_record)))
+ return false;
if (entry_file.Read(file_length - sizeof(eof_record),
reinterpret_cast<char*>(&eof_record),
sizeof(eof_record)) != sizeof(eof_record)) {
« no previous file with comments | « net/disk_cache/blockfile/file_posix.cc ('k') | sandbox/win/src/process_mitigations_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698