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

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, 1 month 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
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..4eea2d06a43c51b59060e015ef6e24a56e34a6b5 100644
--- a/net/disk_cache/simple/simple_test_util.cc
+++ b/net/disk_cache/simple/simple_test_util.cc
@@ -39,6 +39,8 @@ bool RemoveKeySHA256FromEntry(const std::string& key,
return false;
int file_length = entry_file.GetLength();
SimpleFileEOF eof_record;
+ if (file_length < 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 < 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 < 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)) {

Powered by Google App Engine
This is Rietveld 408576698