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

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: Fix ASAN failure 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 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 base::PlatformFile file = GetReadonlyPnaclFD(filename); 1107 base::PlatformFile file = GetReadonlyPnaclFD(filename);
1108 if (file == base::kInvalidPlatformFileValue) { 1108 if (file == base::kInvalidPlatformFileValue) {
1109 load_manager->ReportLoadError( 1109 load_manager->ReportLoadError(
1110 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, 1110 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1111 "The Portable Native Client (pnacl) component is not " 1111 "The Portable Native Client (pnacl) component is not "
1112 "installed. Please consult chrome://components for more " 1112 "installed. Please consult chrome://components for more "
1113 "information."); 1113 "information.");
1114 return PP_FALSE; 1114 return PP_FALSE;
1115 } 1115 }
1116 1116
1117 const int kBufferSize = 1 << 20; 1117 base::PlatformFileInfo file_info;
1118 scoped_ptr<char[]> buffer(new char[kBufferSize]); 1118 if (!GetPlatformFileInfo(file, &file_info)) {
1119 if (base::ReadPlatformFile(file, 0, buffer.get(), kBufferSize) < 0) {
1120 load_manager->ReportLoadError( 1119 load_manager->ReportLoadError(
1121 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, 1120 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1122 std::string("PnaclResources::ReadResourceInfo reading failed for: ") + 1121 std::string("GetPNaClResourceInfo, GetFileInfo failed for: ") +
1123 filename); 1122 filename);
1124 return PP_FALSE; 1123 return PP_FALSE;
1125 } 1124 }
1126 1125
1126 if (file_info.size > 1 << 20) {
1127 load_manager->ReportLoadError(
1128 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1129 std::string("GetPNaClResourceInfo, file too large: ") + filename);
1130 return PP_FALSE;
1131 }
1132
1133 scoped_ptr<char[]> buffer(new char[file_info.size + 1]);
1134 if (buffer.get() == NULL) {
1135 load_manager->ReportLoadError(
1136 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1137 std::string("GetPNaClResourceInfo, couldn't allocate for: ") +
1138 filename);
1139 return PP_FALSE;
1140 }
1141
1142 int rc = base::ReadPlatformFile(file, 0, buffer.get(), file_info.size);
1143 if (rc < 0) {
1144 load_manager->ReportLoadError(
1145 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1146 std::string("GetPNaClResourceInfo, reading failed for: ") + filename);
1147 return PP_FALSE;
1148 }
1149
1150 // Null-terminate the bytes we we read from the file.
1151 buffer.get()[rc] = 0;
1152
1127 // Expect the JSON file to contain a top-level object (dictionary). 1153 // Expect the JSON file to contain a top-level object (dictionary).
1128 Json::Reader json_reader; 1154 Json::Reader json_reader;
1129 Json::Value json_data; 1155 Json::Value json_data;
1130 if (!json_reader.parse(buffer.get(), json_data)) { 1156 if (!json_reader.parse(buffer.get(), json_data)) {
1131 load_manager->ReportLoadError( 1157 load_manager->ReportLoadError(
1132 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, 1158 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1133 std::string("Parsing resource info failed: JSON parse error: ") + 1159 std::string("Parsing resource info failed: JSON parse error: ") +
1134 json_reader.getFormattedErrorMessages()); 1160 json_reader.getFormattedErrorMessages());
1135 return PP_FALSE; 1161 return PP_FALSE;
1136 } 1162 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 &PostMessageToJavaScript 1305 &PostMessageToJavaScript
1280 }; 1306 };
1281 1307
1282 } // namespace 1308 } // namespace
1283 1309
1284 const PPB_NaCl_Private* GetNaClPrivateInterface() { 1310 const PPB_NaCl_Private* GetNaClPrivateInterface() {
1285 return &nacl_interface; 1311 return &nacl_interface;
1286 } 1312 }
1287 1313
1288 } // namespace nacl 1314 } // 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