Commit c1f16bd8 authored by thestig's avatar thestig Committed by Commit bot

Cleanup some PPAPI proxy code.

Check for potential overflows in PDFResource::SearchString().

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

Cr-Commit-Position: refs/heads/master@{#330675}
parent 78cbe4a3
...@@ -42,7 +42,7 @@ PP_Bool FlashFontFileResource::GetFontTable(uint32_t table, ...@@ -42,7 +42,7 @@ PP_Bool FlashFontFileResource::GetFontTable(uint32_t table,
RENDERER, PpapiHostMsg_FlashFontFile_Create(description_, charset_)); RENDERER, PpapiHostMsg_FlashFontFile_Create(description_, charset_));
} }
std::string* contents = GetFontTable(table); const std::string* contents = GetFontTable(table);
if (!contents) { if (!contents) {
std::string out_contents; std::string out_contents;
int32_t result = SyncCall<PpapiPluginMsg_FlashFontFile_GetFontTableReply>( int32_t result = SyncCall<PpapiPluginMsg_FlashFontFile_GetFontTableReply>(
...@@ -64,18 +64,17 @@ PP_Bool FlashFontFileResource::GetFontTable(uint32_t table, ...@@ -64,18 +64,17 @@ PP_Bool FlashFontFileResource::GetFontTable(uint32_t table,
return PP_TRUE; return PP_TRUE;
} }
std::string* FlashFontFileResource::GetFontTable(uint32_t table) const { const std::string* FlashFontFileResource::GetFontTable(uint32_t table) const {
FontTableMap::const_iterator found = font_tables_.find(table); FontTableMap::const_iterator found = font_tables_.find(table);
if (found == font_tables_.end()) return (found != font_tables_.end()) ? found->second : nullptr;
return NULL;
return found->second.get();
} }
std::string* FlashFontFileResource::AddFontTable(uint32_t table, const std::string* FlashFontFileResource::AddFontTable(
uint32_t table,
const std::string& contents) { const std::string& contents) {
linked_ptr<std::string> heap_string(new std::string(contents)); FontTableMap::const_iterator it =
font_tables_[table] = heap_string; font_tables_.set(table, make_scoped_ptr(new std::string(contents)));
return heap_string.get(); return it->second;
} }
} // namespace proxy } // namespace proxy
......
...@@ -5,12 +5,9 @@ ...@@ -5,12 +5,9 @@
#ifndef PPAPI_PROXY_FLASH_FONT_FILE_RESOURCE_H_ #ifndef PPAPI_PROXY_FLASH_FONT_FILE_RESOURCE_H_
#define PPAPI_PROXY_FLASH_FONT_FILE_RESOURCE_H_ #define PPAPI_PROXY_FLASH_FONT_FILE_RESOURCE_H_
#include <map>
#include <string> #include <string>
#include "base/basictypes.h" #include "base/containers/scoped_ptr_hash_map.h"
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
#include "ppapi/c/private/pp_private_font_charset.h" #include "ppapi/c/private/pp_private_font_charset.h"
#include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/plugin_resource.h"
#include "ppapi/proxy/serialized_structs.h" #include "ppapi/proxy/serialized_structs.h"
...@@ -42,15 +39,16 @@ class FlashFontFileResource : public PluginResource, ...@@ -42,15 +39,16 @@ class FlashFontFileResource : public PluginResource,
private: private:
// Sees if we have a cache of the font table and returns a pointer to it. // Sees if we have a cache of the font table and returns a pointer to it.
// Returns NULL if we don't have it. // Returns NULL if we don't have it.
std::string* GetFontTable(uint32_t table) const; const std::string* GetFontTable(uint32_t table) const;
std::string* AddFontTable(uint32_t table, const std::string& contents); const std::string* AddFontTable(uint32_t table, const std::string& contents);
typedef std::map<uint32_t, linked_ptr<std::string> > FontTableMap; using FontTableMap =
base::ScopedPtrHashMap<uint32_t, scoped_ptr<std::string>>;
FontTableMap font_tables_; FontTableMap font_tables_;
SerializedFontDescription description_; SerializedFontDescription description_;
PP_PrivateFontCharset charset_; const PP_PrivateFontCharset charset_;
DISALLOW_COPY_AND_ASSIGN(FlashFontFileResource); DISALLOW_COPY_AND_ASSIGN(FlashFontFileResource);
}; };
......
...@@ -98,13 +98,16 @@ void PDFResource::SearchString(const unsigned short* input_string, ...@@ -98,13 +98,16 @@ void PDFResource::SearchString(const unsigned short* input_string,
DCHECK(status == U_ZERO_ERROR); DCHECK(status == U_ZERO_ERROR);
} }
*count = static_cast<uint32_t>(pp_results.size()); if (pp_results.empty() ||
if (*count) { pp_results.size() > std::numeric_limits<uint32_t>::max() ||
*results = reinterpret_cast<PP_PrivateFindResult*>(malloc( pp_results.size() > SIZE_MAX / sizeof(PP_PrivateFindResult)) {
*count * sizeof(PP_PrivateFindResult))); *count = 0;
memcpy(*results, &pp_results[0], *count * sizeof(PP_PrivateFindResult)); *results = nullptr;
} else { } else {
*results = NULL; *count = static_cast<uint32_t>(pp_results.size());
const size_t result_size = pp_results.size() * sizeof(PP_PrivateFindResult);
*results = reinterpret_cast<PP_PrivateFindResult*>(malloc(result_size));
memcpy(*results, &pp_results[0], result_size);
} }
usearch_close(searcher); usearch_close(searcher);
......
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