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

Side by Side Diff: ppapi/proxy/pdf_resource.cc

Issue 1147883002: Cleanup some PPAPI proxy code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix accidental memcpy removal Created 5 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « ppapi/proxy/flash_font_file_resource.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/pdf_resource.h" 5 #include "ppapi/proxy/pdf_resource.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 while (match_start != USEARCH_DONE) { 91 while (match_start != USEARCH_DONE) {
92 int32_t matched_length = usearch_getMatchedLength(searcher); 92 int32_t matched_length = usearch_getMatchedLength(searcher);
93 PP_PrivateFindResult result; 93 PP_PrivateFindResult result;
94 result.start_index = match_start; 94 result.start_index = match_start;
95 result.length = matched_length; 95 result.length = matched_length;
96 pp_results.push_back(result); 96 pp_results.push_back(result);
97 match_start = usearch_next(searcher, &status); 97 match_start = usearch_next(searcher, &status);
98 DCHECK(status == U_ZERO_ERROR); 98 DCHECK(status == U_ZERO_ERROR);
99 } 99 }
100 100
101 *count = static_cast<uint32_t>(pp_results.size()); 101 if (pp_results.empty() ||
102 if (*count) { 102 pp_results.size() > std::numeric_limits<uint32_t>::max() ||
103 *results = reinterpret_cast<PP_PrivateFindResult*>(malloc( 103 pp_results.size() >
104 *count * sizeof(PP_PrivateFindResult))); 104 std::numeric_limits<size_t>::max() / sizeof(PP_PrivateFindResult)) {
raymes 2015/05/20 00:26:48 Would it be simpler just to have some large consta
Lei Zhang 2015/05/20 00:30:48 I can replace std::numeric_limits<size_t>::max() w
Lei Zhang 2015/05/20 00:46:34 Done in patch set 3. But in general, the security
105 memcpy(*results, &pp_results[0], *count * sizeof(PP_PrivateFindResult)); 105 *count = 0;
106 *results = nullptr;
106 } else { 107 } else {
107 *results = NULL; 108 *count = static_cast<uint32_t>(pp_results.size());
109 const size_t result_size = pp_results.size() * sizeof(PP_PrivateFindResult);
110 *results = reinterpret_cast<PP_PrivateFindResult*>(malloc(result_size));
111 memcpy(*results, &pp_results[0], result_size);
108 } 112 }
109 113
110 usearch_close(searcher); 114 usearch_close(searcher);
111 } 115 }
112 116
113 void PDFResource::DidStartLoading() { 117 void PDFResource::DidStartLoading() {
114 Post(RENDERER, PpapiHostMsg_PDF_DidStartLoading()); 118 Post(RENDERER, PpapiHostMsg_PDF_DidStartLoading());
115 } 119 }
116 120
117 void PDFResource::DidStopLoading() { 121 void PDFResource::DidStopLoading() {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 void PDFResource::GetV8ExternalSnapshotData(const char** natives_data_out, 213 void PDFResource::GetV8ExternalSnapshotData(const char** natives_data_out,
210 int* natives_size_out, 214 int* natives_size_out,
211 const char** snapshot_data_out, 215 const char** snapshot_data_out,
212 int* snapshot_size_out) { 216 int* snapshot_size_out) {
213 gin::V8Initializer::GetV8ExternalSnapshotData( 217 gin::V8Initializer::GetV8ExternalSnapshotData(
214 natives_data_out, natives_size_out, snapshot_data_out, snapshot_size_out); 218 natives_data_out, natives_size_out, snapshot_data_out, snapshot_size_out);
215 } 219 }
216 220
217 } // namespace proxy 221 } // namespace proxy
218 } // namespace ppapi 222 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/flash_font_file_resource.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698