Index: base/files/memory_mapped_file_win.cc |
diff --git a/base/files/memory_mapped_file_win.cc b/base/files/memory_mapped_file_win.cc |
index f3822873bfdddb877bd73afd9fa2548ca5cd83f2..74d8619e9a6a99592bbf30529c386066b80e738c 100644 |
--- a/base/files/memory_mapped_file_win.cc |
+++ b/base/files/memory_mapped_file_win.cc |
@@ -18,7 +18,7 @@ bool MemoryMappedFile::InitializeAsImageSection(const FilePath& file_name) { |
return Initialize(file_name); |
} |
-bool MemoryMappedFile::MapFileToMemory() { |
+bool MemoryMappedFile::MapFileToMemory(const base::File::Region& region) { |
ThreadRestrictions::AssertIOAllowed(); |
if (!file_.IsValid()) |
@@ -27,6 +27,10 @@ bool MemoryMappedFile::MapFileToMemory() { |
int64 len = file_.GetLength(); |
if (len <= 0 || len > kint32max) |
mkosiba (inactive)
2014/07/17 00:38:01
do we want to apply the same check to offset? then
Primiano Tucci (use gerrit)
2014/07/17 01:15:17
Actually, now that I think more about this, we sh
|
return false; |
+ if (region.offset + region.size > len) { |
+ DLOG(ERROR) << "Region bounds invalid"; |
+ return false; |
+ } |
length_ = static_cast<size_t>(len); |
int flags = image_ ? SEC_IMAGE | PAGE_READONLY : PAGE_READONLY; |
@@ -36,8 +40,12 @@ bool MemoryMappedFile::MapFileToMemory() { |
if (!file_mapping_.IsValid()) |
return false; |
+ LARGE_INTEGER offset = {.QuadPart = region.offset}; |
data_ = static_cast<uint8*>(::MapViewOfFile(file_mapping_.Get(), |
- FILE_MAP_READ, 0, 0, 0)); |
+ FILE_MAP_READ, |
+ offset.HighPart, |
+ offset.LowPart, |
+ region.size)); |
return data_ != NULL; |
} |