Index: src/wasm/module-decoder.cc |
diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc |
index 8794fe64351ca17add7c44f5fa149f82796b0a82..272a60ddaa6383e3503c606352d9d77fb73b2faa 100644 |
--- a/src/wasm/module-decoder.cc |
+++ b/src/wasm/module-decoder.cc |
@@ -910,6 +910,21 @@ class ModuleDecoder : public Decoder { |
switch (opcode) { |
case kExprGetGlobal: { |
GlobalIndexOperand operand(this, pc() - 1); |
+ if (module->globals.size() <= operand.index) { |
+ error("global index is out of bounds"); |
+ expr.kind = WasmInitExpr::kNone; |
+ expr.val.i32_const = 0; |
+ break; |
+ } |
+ WasmGlobal* global = &module->globals[operand.index]; |
+ if (global->mutability || !global->imported) { |
+ error( |
+ "only immutable imported globals can be used in initializer " |
+ "expressions"); |
+ expr.kind = WasmInitExpr::kNone; |
+ expr.val.i32_const = 0; |
+ break; |
+ } |
expr.kind = WasmInitExpr::kGlobalIndex; |
expr.val.global_index = operand.index; |
len = operand.length; |