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

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

Issue 2410953003: [wasm] Fix decoding of shared global index space (Closed)
Patch Set: Increase allocation limit Created 4 years, 2 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 | « no previous file | src/wasm/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 "src/wasm/module-decoder.h" 5 #include "src/wasm/module-decoder.h"
6 6
7 #include "src/base/functional.h" 7 #include "src/base/functional.h"
8 #include "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/flags.h" 9 #include "src/flags.h"
10 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 consume_resizable_limits("memory", "pages", WasmModule::kMaxLegalPages, 390 consume_resizable_limits("memory", "pages", WasmModule::kMaxLegalPages,
391 &module->min_mem_pages, 391 &module->min_mem_pages,
392 &module->max_mem_pages); 392 &module->max_mem_pages);
393 } 393 }
394 section_iter.advance(); 394 section_iter.advance();
395 } 395 }
396 396
397 // ===== Global section ================================================== 397 // ===== Global section ==================================================
398 if (section_iter.section_code() == kGlobalSectionCode) { 398 if (section_iter.section_code() == kGlobalSectionCode) {
399 uint32_t globals_count = consume_u32v("globals count"); 399 uint32_t globals_count = consume_u32v("globals count");
400 module->globals.reserve(SafeReserve(globals_count)); 400 uint32_t imported_globals = static_cast<uint32_t>(module->globals.size());
401 if (!IsWithinLimit(std::numeric_limits<int32_t>::max(), globals_count,
402 imported_globals)) {
403 error(pos, pos, "too many imported+defined globals: %u + %u",
404 imported_globals, globals_count);
405 }
406 module->globals.reserve(SafeReserve(imported_globals + globals_count));
401 for (uint32_t i = 0; ok() && i < globals_count; ++i) { 407 for (uint32_t i = 0; ok() && i < globals_count; ++i) {
402 TRACE("DecodeGlobal[%d] module+%d\n", i, 408 TRACE("DecodeGlobal[%d] module+%d\n", i,
403 static_cast<int>(pc_ - start_)); 409 static_cast<int>(pc_ - start_));
404 // Add an uninitialized global and pass a pointer to it. 410 // Add an uninitialized global and pass a pointer to it.
405 module->globals.push_back( 411 module->globals.push_back(
406 {kAstStmt, false, WasmInitExpr(), 0, false, false}); 412 {kAstStmt, false, WasmInitExpr(), 0, false, false});
407 WasmGlobal* global = &module->globals.back(); 413 WasmGlobal* global = &module->globals.back();
408 DecodeGlobalInModule(module, i, global); 414 DecodeGlobalInModule(module, i + imported_globals, global);
409 } 415 }
410 section_iter.advance(); 416 section_iter.advance();
411 } 417 }
412 418
413 // ===== Export section ================================================== 419 // ===== Export section ==================================================
414 if (section_iter.section_code() == kExportSectionCode) { 420 if (section_iter.section_code() == kExportSectionCode) {
415 uint32_t export_table_count = consume_u32v("export table count"); 421 uint32_t export_table_count = consume_u32v("export table count");
416 module->export_table.reserve(SafeReserve(export_table_count)); 422 module->export_table.reserve(SafeReserve(export_table_count));
417 for (uint32_t i = 0; ok() && i < export_table_count; ++i) { 423 for (uint32_t i = 0; ok() && i < export_table_count; ++i) {
418 TRACE("DecodeExportTable[%d] module+%d\n", i, 424 TRACE("DecodeExportTable[%d] module+%d\n", i,
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 void DecodeGlobalInModule(WasmModule* module, uint32_t index, 668 void DecodeGlobalInModule(WasmModule* module, uint32_t index,
663 WasmGlobal* global) { 669 WasmGlobal* global) {
664 global->type = consume_value_type(); 670 global->type = consume_value_type();
665 global->mutability = consume_u8("mutability") != 0; 671 global->mutability = consume_u8("mutability") != 0;
666 const byte* pos = pc(); 672 const byte* pos = pc();
667 global->init = consume_init_expr(module, kAstStmt); 673 global->init = consume_init_expr(module, kAstStmt);
668 switch (global->init.kind) { 674 switch (global->init.kind) {
669 case WasmInitExpr::kGlobalIndex: { 675 case WasmInitExpr::kGlobalIndex: {
670 uint32_t other_index = global->init.val.global_index; 676 uint32_t other_index = global->init.val.global_index;
671 if (other_index >= index) { 677 if (other_index >= index) {
672 error("invalid global index in init expression"); 678 error(pos, pos,
679 "invalid global index in init expression, "
680 "index %u, other_index %u",
681 index, other_index);
673 } else if (module->globals[other_index].type != global->type) { 682 } else if (module->globals[other_index].type != global->type) {
674 error(pos, pos, 683 error(pos, pos,
675 "type mismatch in global initialization " 684 "type mismatch in global initialization "
676 "(from global #%u), expected %s, got %s", 685 "(from global #%u), expected %s, got %s",
677 other_index, WasmOpcodes::TypeName(global->type), 686 other_index, WasmOpcodes::TypeName(global->type),
678 WasmOpcodes::TypeName(module->globals[other_index].type)); 687 WasmOpcodes::TypeName(module->globals[other_index].type));
679 } 688 }
680 break; 689 break;
681 } 690 }
682 default: 691 default:
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 decoder.consume_bytes(size); 1147 decoder.consume_bytes(size);
1139 } 1148 }
1140 if (decoder.more()) decoder.error("unexpected additional bytes"); 1149 if (decoder.more()) decoder.error("unexpected additional bytes");
1141 1150
1142 return decoder.toResult(std::move(table)); 1151 return decoder.toResult(std::move(table));
1143 } 1152 }
1144 1153
1145 } // namespace wasm 1154 } // namespace wasm
1146 } // namespace internal 1155 } // namespace internal
1147 } // namespace v8 1156 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698