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

Side by Side Diff: components/nacl/renderer/ppb_nacl_private_impl.cc

Issue 274673002: Pepper: Fix crash on allocation failure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/nacl/renderer/ppb_nacl_private_impl.h" 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h"
6 6
7 #include <numeric> 7 #include <numeric>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 base::PlatformFile file = GetReadonlyPnaclFD(filename); 1129 base::PlatformFile file = GetReadonlyPnaclFD(filename);
1130 if (file == base::kInvalidPlatformFileValue) { 1130 if (file == base::kInvalidPlatformFileValue) {
1131 load_manager->ReportLoadError( 1131 load_manager->ReportLoadError(
1132 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, 1132 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1133 "The Portable Native Client (pnacl) component is not " 1133 "The Portable Native Client (pnacl) component is not "
1134 "installed. Please consult chrome://components for more " 1134 "installed. Please consult chrome://components for more "
1135 "information."); 1135 "information.");
1136 return PP_FALSE; 1136 return PP_FALSE;
1137 } 1137 }
1138 1138
1139 const int kBufferSize = 1 << 20; 1139 base::PlatformFileInfo file_info;
1140 scoped_ptr<char[]> buffer(new char[kBufferSize]); 1140 if (!GetPlatformFileInfo(file, &file_info)) {
1141 if (base::ReadPlatformFile(file, 0, buffer.get(), kBufferSize) < 0) {
1142 load_manager->ReportLoadError( 1141 load_manager->ReportLoadError(
1143 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, 1142 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1144 std::string("PnaclResources::ReadResourceInfo reading failed for: ") + 1143 std::string("GetPNaClResourceInfo, GetFileInfo failed for: ") +
1145 filename); 1144 filename);
1146 return PP_FALSE; 1145 return PP_FALSE;
1147 } 1146 }
1148 1147
1148 if (file_info.size > 1 << 20) {
bbudge 2014/05/08 00:15:59 The old behavior seems bad since it would only do
1149 load_manager->ReportLoadError(
1150 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1151 std::string("GetPNaClResourceInfo, file too large: ") + filename);
1152 return PP_FALSE;
1153 }
1154
1155 scoped_ptr<char[]> buffer(new char[file_info.size]);
1156 if (buffer.get() == NULL) {
1157 load_manager->ReportLoadError(
1158 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1159 std::string("GetPNaClResourceInfo, couldn't allocate for: ") +
1160 filename);
1161 return PP_FALSE;
1162 }
1163
1164 if (base::ReadPlatformFile(file, 0, buffer.get(), file_info.size) < 0) {
1165 load_manager->ReportLoadError(
1166 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1167 std::string("GetPNaClResourceInfo, reading failed for: ") + filename);
1168 return PP_FALSE;
1169 }
1170
1149 // Expect the JSON file to contain a top-level object (dictionary). 1171 // Expect the JSON file to contain a top-level object (dictionary).
1150 Json::Reader json_reader; 1172 Json::Reader json_reader;
1151 Json::Value json_data; 1173 Json::Value json_data;
1152 if (!json_reader.parse(buffer.get(), json_data)) { 1174 if (!json_reader.parse(buffer.get(), json_data)) {
1153 load_manager->ReportLoadError( 1175 load_manager->ReportLoadError(
1154 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, 1176 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1155 std::string("Parsing resource info failed: JSON parse error: ") + 1177 std::string("Parsing resource info failed: JSON parse error: ") +
1156 json_reader.getFormattedErrorMessages()); 1178 json_reader.getFormattedErrorMessages());
1157 return PP_FALSE; 1179 return PP_FALSE;
1158 } 1180 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 &GetCpuFeatureAttrs 1303 &GetCpuFeatureAttrs
1282 }; 1304 };
1283 1305
1284 } // namespace 1306 } // namespace
1285 1307
1286 const PPB_NaCl_Private* GetNaClPrivateInterface() { 1308 const PPB_NaCl_Private* GetNaClPrivateInterface() {
1287 return &nacl_interface; 1309 return &nacl_interface;
1288 } 1310 }
1289 1311
1290 } // namespace nacl 1312 } // namespace nacl
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698