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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/wasm/wasm-module.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/module-decoder.cc
diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc
index 0f8637f32eeb1785c8a45bad1f585510d13e1f64..bbfcd0870695c5bf353d903e5c2ba0422f9db844 100644
--- a/src/wasm/module-decoder.cc
+++ b/src/wasm/module-decoder.cc
@@ -397,7 +397,13 @@ class ModuleDecoder : public Decoder {
// ===== Global section ==================================================
if (section_iter.section_code() == kGlobalSectionCode) {
uint32_t globals_count = consume_u32v("globals count");
- module->globals.reserve(SafeReserve(globals_count));
+ uint32_t imported_globals = static_cast<uint32_t>(module->globals.size());
+ if (!IsWithinLimit(std::numeric_limits<int32_t>::max(), globals_count,
+ imported_globals)) {
+ error(pos, pos, "too many imported+defined globals: %u + %u",
+ imported_globals, globals_count);
+ }
+ module->globals.reserve(SafeReserve(imported_globals + globals_count));
for (uint32_t i = 0; ok() && i < globals_count; ++i) {
TRACE("DecodeGlobal[%d] module+%d\n", i,
static_cast<int>(pc_ - start_));
@@ -405,7 +411,7 @@ class ModuleDecoder : public Decoder {
module->globals.push_back(
{kAstStmt, false, WasmInitExpr(), 0, false, false});
WasmGlobal* global = &module->globals.back();
- DecodeGlobalInModule(module, i, global);
+ DecodeGlobalInModule(module, i + imported_globals, global);
}
section_iter.advance();
}
@@ -669,7 +675,10 @@ class ModuleDecoder : public Decoder {
case WasmInitExpr::kGlobalIndex: {
uint32_t other_index = global->init.val.global_index;
if (other_index >= index) {
- error("invalid global index in init expression");
+ error(pos, pos,
+ "invalid global index in init expression, "
+ "index %u, other_index %u",
+ index, other_index);
} else if (module->globals[other_index].type != global->type) {
error(pos, pos,
"type mismatch in global initialization "
« 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