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

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2483053005: [wasm] Check data segments for zero-sized memory. (Closed)
Patch Set: Use a different formatter string Created 4 years, 1 month 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 | « no previous file | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project 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 <memory> 5 #include <memory>
6 6
7 #include "src/base/atomic-utils.h" 7 #include "src/base/atomic-utils.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 9
10 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 1146
1147 uint32_t old_mem_size = compiled_module_->mem_size(); 1147 uint32_t old_mem_size = compiled_module_->mem_size();
1148 Address old_mem_start = 1148 Address old_mem_start =
1149 compiled_module_->has_memory() 1149 compiled_module_->has_memory()
1150 ? static_cast<Address>( 1150 ? static_cast<Address>(
1151 compiled_module_->memory()->backing_store()) 1151 compiled_module_->memory()->backing_store())
1152 : nullptr; 1152 : nullptr;
1153 RelocateMemoryReferencesInCode(code_table, old_mem_start, mem_start, 1153 RelocateMemoryReferencesInCode(code_table, old_mem_start, mem_start,
1154 old_mem_size, mem_size); 1154 old_mem_size, mem_size);
1155 compiled_module_->set_memory(memory_); 1155 compiled_module_->set_memory(memory_);
1156 } else {
1157 LoadDataSegments(nullptr, 0);
1156 } 1158 }
1157 1159
1158 //-------------------------------------------------------------------------- 1160 //--------------------------------------------------------------------------
1159 // Set up the runtime support for the new instance. 1161 // Set up the runtime support for the new instance.
1160 //-------------------------------------------------------------------------- 1162 //--------------------------------------------------------------------------
1161 Handle<WeakCell> weak_link = factory->NewWeakCell(instance); 1163 Handle<WeakCell> weak_link = factory->NewWeakCell(instance);
1162 1164
1163 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs; 1165 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs;
1164 i < code_table->length(); ++i) { 1166 i < code_table->length(); ++i) {
1165 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); 1167 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 import_name); 1344 import_name);
1343 } 1345 }
1344 } else { 1346 } else {
1345 // No function specified. Use the "default export". 1347 // No function specified. Use the "default export".
1346 result = module; 1348 result = module;
1347 } 1349 }
1348 1350
1349 return result; 1351 return result;
1350 } 1352 }
1351 1353
1352 uint32_t EvalUint32InitExpr(WasmInitExpr& expr) { 1354 uint32_t EvalUint32InitExpr(const WasmInitExpr& expr) {
1353 switch (expr.kind) { 1355 switch (expr.kind) {
1354 case WasmInitExpr::kI32Const: 1356 case WasmInitExpr::kI32Const:
1355 return expr.val.i32_const; 1357 return expr.val.i32_const;
1356 case WasmInitExpr::kGlobalIndex: { 1358 case WasmInitExpr::kGlobalIndex: {
1357 uint32_t offset = module_->globals[expr.val.global_index].offset; 1359 uint32_t offset = module_->globals[expr.val.global_index].offset;
1358 return *reinterpret_cast<uint32_t*>(raw_buffer_ptr(globals_, offset)); 1360 return *reinterpret_cast<uint32_t*>(raw_buffer_ptr(globals_, offset));
1359 } 1361 }
1360 default: 1362 default:
1361 UNREACHABLE(); 1363 UNREACHABLE();
1362 return 0; 1364 return 0;
1363 } 1365 }
1364 } 1366 }
1365 1367
1366 // Load data segments into the memory. 1368 // Load data segments into the memory.
1367 void LoadDataSegments(Address mem_addr, size_t mem_size) { 1369 void LoadDataSegments(Address mem_addr, size_t mem_size) {
1368 Handle<SeqOneByteString> module_bytes = compiled_module_->module_bytes(); 1370 Handle<SeqOneByteString> module_bytes = compiled_module_->module_bytes();
1369 for (auto segment : module_->data_segments) { 1371 for (const WasmDataSegment& segment : module_->data_segments) {
1372 uint32_t source_size = segment.source_size;
1373 // Segments of size == 0 are just nops.
1374 if (source_size == 0) continue;
1370 uint32_t dest_offset = EvalUint32InitExpr(segment.dest_addr); 1375 uint32_t dest_offset = EvalUint32InitExpr(segment.dest_addr);
1371 uint32_t source_size = segment.source_size;
1372 if (dest_offset >= mem_size || source_size >= mem_size || 1376 if (dest_offset >= mem_size || source_size >= mem_size ||
1373 dest_offset > (mem_size - source_size)) { 1377 dest_offset > (mem_size - source_size)) {
1374 thrower_->RangeError( 1378 thrower_->TypeError("data segment (start = %" PRIu32 ", size = %" PRIu32
1375 "data segment (start = %u, size = %u) does not fit into memory " 1379 ") does not fit into memory "
1376 "(size = %zu)", 1380 "(size = %" PRIu64 ")",
1377 dest_offset, source_size, mem_size); 1381 dest_offset, source_size,
1382 static_cast<uint64_t>(mem_size));
1378 return; 1383 return;
1379 } 1384 }
1380 byte* dest = mem_addr + dest_offset; 1385 byte* dest = mem_addr + dest_offset;
1381 const byte* src = reinterpret_cast<const byte*>( 1386 const byte* src = reinterpret_cast<const byte*>(
1382 module_bytes->GetCharsAddress() + segment.source_offset); 1387 module_bytes->GetCharsAddress() + segment.source_offset);
1383 memcpy(dest, src, source_size); 1388 memcpy(dest, src, source_size);
1384 } 1389 }
1385 } 1390 }
1386 1391
1387 void WriteGlobalValue(WasmGlobal& global, Handle<Object> value) { 1392 void WriteGlobalValue(WasmGlobal& global, Handle<Object> value) {
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
2259 CHECK_NOT_NULL(result.val); 2264 CHECK_NOT_NULL(result.val);
2260 module = const_cast<WasmModule*>(result.val); 2265 module = const_cast<WasmModule*>(result.val);
2261 } 2266 }
2262 2267
2263 Handle<WasmModuleWrapper> module_wrapper = 2268 Handle<WasmModuleWrapper> module_wrapper =
2264 WasmModuleWrapper::New(isolate, module); 2269 WasmModuleWrapper::New(isolate, module);
2265 2270
2266 compiled_module->set_module_wrapper(module_wrapper); 2271 compiled_module->set_module_wrapper(module_wrapper);
2267 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); 2272 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module));
2268 } 2273 }
OLDNEW
« no previous file with comments | « no previous file | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698