From ccec65e3d0c980bb1079fd0946f48dea069d224e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 16 Aug 2016 15:40:22 -0700 Subject: some additional validations --- src/wasm-s-parser.h | 5 +++++ src/wasm-validator.h | 11 +++++++++++ 2 files changed, 16 insertions(+) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 3f61b113f..a4dd60532 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1472,7 +1472,11 @@ private: wasm.addGlobal(global.release()); } + bool seenTable = false; + void parseTable(Element& s) { + seenTable = true; + if (s.size() == 1) return; // empty table in old notation if (!s[1]->dollared()) { if (s[1]->str() == ANYFUNC) { @@ -1495,6 +1499,7 @@ private: } void parseElem(Element& s) { + if (!seenTable) throw ParseException("elem without table", s.line, s.col); Index i = 1; Expression* offset; if (s[i]->isList()) { diff --git a/src/wasm-validator.h b/src/wasm-validator.h index 0c3acaf6d..ffdd2a2b7 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -347,10 +347,21 @@ public: } returnType = unreachable; } + + bool isConstant(Expression* curr) { + return curr->is(); + } + void visitMemory(Memory *curr) { shouldBeFalse(curr->initial > curr->max, "memory", "memory max >= initial"); shouldBeTrue(curr->max <= Memory::kMaxSize, "memory", "max memory must be <= 4GB"); } + void visitTable(Table* curr) { + for (auto& segment : curr->segments) { + shouldBeEqual(segment.offset->type, i32, segment.offset, "segment offset should be i32"); + shouldBeTrue(isConstant(segment.offset), segment.offset, "segment offset should be constant"); + } + } void visitModule(Module *curr) { // exports std::set exportNames; -- cgit v1.2.3