Index: base/files/memory_mapped_file_posix.cc |
diff --git a/base/files/memory_mapped_file_posix.cc b/base/files/memory_mapped_file_posix.cc |
index 5d7e0079992d835d32aad565d4836600257cb4b5..d04a1ff1c61fe20371e91a9b5dafbf10acf41f34 100644 |
--- a/base/files/memory_mapped_file_posix.cc |
+++ b/base/files/memory_mapped_file_posix.cc |
@@ -16,18 +16,28 @@ namespace base { |
MemoryMappedFile::MemoryMappedFile() : data_(NULL), length_(0) { |
} |
-bool MemoryMappedFile::MapFileToMemory() { |
+bool MemoryMappedFile::MapFileToMemory(const base::File::Region& region) { |
ThreadRestrictions::AssertIOAllowed(); |
- struct stat file_stat; |
- if (fstat(file_.GetPlatformFile(), &file_stat) == -1 ) { |
+ int64 file_len = file_.GetLength(); |
+ |
+ if (file_len == -1) { |
DPLOG(ERROR) << "fstat " << file_.GetPlatformFile(); |
return false; |
} |
- length_ = file_stat.st_size; |
- data_ = static_cast<uint8*>( |
- mmap(NULL, length_, PROT_READ, MAP_SHARED, file_.GetPlatformFile(), 0)); |
+ if (region.offset + region.size > file_.GetLength()) { |
+ DLOG(ERROR) << "Region bounds invalid"; |
+ return false; |
+ } |
+ |
+ length_ = static_cast<size_t>(region.size); |
+ data_ = static_cast<uint8*>(mmap(NULL, |
+ length_, |
+ PROT_READ, |
+ MAP_SHARED, |
+ file_.GetPlatformFile(), |
+ region.offset)); |
if (data_ == MAP_FAILED) |
DPLOG(ERROR) << "mmap " << file_.GetPlatformFile(); |