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

Unified Diff: src/wasm/module-decoder.cc

Issue 2410953003: [wasm] Fix decoding of shared global index space (Closed)
Patch Set: review comment 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..10c66b858ed8596c92842da01bb7e956c32df3cf 100644
--- a/src/wasm/module-decoder.cc
+++ b/src/wasm/module-decoder.cc
@@ -397,7 +397,12 @@ 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(kMaxReserve, globals_count, imported_globals)) {
Derek Schuff 2016/10/12 05:35:19 OK, so I was afraid this would be a problem; I was
+ 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 +410,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();
}
@@ -617,7 +622,6 @@ class ModuleDecoder : public Decoder {
uint32_t SafeReserve(uint32_t count) {
// Avoid OOM by only reserving up to a certain size.
- const uint32_t kMaxReserve = 20000;
return count < kMaxReserve ? count : kMaxReserve;
}
@@ -656,6 +660,8 @@ class ModuleDecoder : public Decoder {
ModuleResult result_;
ModuleOrigin origin_;
+ static const uint32_t kMaxReserve = 20000;
+
uint32_t off(const byte* ptr) { return static_cast<uint32_t>(ptr - start_); }
// Decodes a single global entry inside a module starting at {pc_}.
@@ -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