OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 |
OLD | NEW |