Commit bebcbc64 authored by shrikant's avatar shrikant Committed by Commit bot

Added few validations in Direct Write Font Cache code.

- Added exclusive_write while writing to cache file, so that if there is any
case where two utility processes try to write to cache at same time, it could be prevented.
- Also added check to read minimum structure size bytes.

BUG=434503
R=cpu,ananta

Review URL: https://codereview.chromium.org/733253005

Cr-Commit-Position: refs/heads/master@{#305105}
parent 8a51976d
...@@ -281,13 +281,10 @@ class FontCacheWriter { ...@@ -281,13 +281,10 @@ class FontCacheWriter {
// Function to create static font cache file. // Function to create static font cache file.
bool Create(const wchar_t* file_name) { bool Create(const wchar_t* file_name) {
static_cache_.reset(new base::File(base::FilePath(file_name), static_cache_.reset(new base::File(base::FilePath(file_name),
base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE)); base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE |
base::File::FLAG_EXCLUSIVE_WRITE));
if (!static_cache_->IsValid()) { if (!static_cache_->IsValid()) {
static_cache_.reset(); static_cache_.reset();
// TODO(shrikant): Convert this CHECK to DCHECK post canary.
// We have all fallbacks built in, so if we are not able to create
// static cache, browser can still run with old way of loading all fonts.
CHECK(FALSE);
return false; return false;
} }
CacheFileHeader header; CacheFileHeader header;
...@@ -911,7 +908,7 @@ bool FontCollectionLoader::LoadCacheFile() { ...@@ -911,7 +908,7 @@ bool FontCollectionLoader::LoadCacheFile() {
void FontCollectionLoader::EnterStaticCacheMode(const WCHAR* file_name) { void FontCollectionLoader::EnterStaticCacheMode(const WCHAR* file_name) {
cache_writer_.reset(new FontCacheWriter()); cache_writer_.reset(new FontCacheWriter());
cache_writer_->Create(file_name); if (cache_writer_->Create(file_name))
create_static_cache_ = true; create_static_cache_ = true;
} }
...@@ -956,7 +953,9 @@ bool FontCollectionLoader::ValidateAndLoadCacheMap() { ...@@ -956,7 +953,9 @@ bool FontCollectionLoader::ValidateAndLoadCacheMap() {
table_entry = iter->second; table_entry = iter->second;
} }
table_entry->file_size = entry->file_size; table_entry->file_size = entry->file_size;
for (DWORD idx = 0; current_ptr < mem_file_end && idx < entry->entry_count; for (DWORD idx = 0;
(current_ptr + sizeof(CacheFileOffsetEntry)) < mem_file_end &&
idx < entry->entry_count;
idx++) { idx++) {
CacheFileOffsetEntry* offset_entry = CacheFileOffsetEntry* offset_entry =
reinterpret_cast<CacheFileOffsetEntry*>(current_ptr); reinterpret_cast<CacheFileOffsetEntry*>(current_ptr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment