summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-05-20 06:09:08 -0700
committerGitHub <noreply@github.com>2021-05-20 06:09:08 -0700
commit35f9da76d53401ba4de054f4db631ce4177b32f1 (patch)
tree718405260759afdf79c1a41f4708b35bfc182bed /src
parent3ecad7a543e4ff1395e64b91efbddbbd0d9710a2 (diff)
downloadbinaryen-35f9da76d53401ba4de054f4db631ce4177b32f1.tar.gz
binaryen-35f9da76d53401ba4de054f4db631ce4177b32f1.tar.bz2
binaryen-35f9da76d53401ba4de054f4db631ce4177b32f1.zip
[Wasm GC] Validate struct.get/set heap types early in text parsing (#3897)
We must do that before assuming the type is a heap type in getStructIndex, or we'd hit an assert there.
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-s-parser.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index e6584972e..016858395 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -2628,6 +2628,9 @@ Index SExpressionWasmBuilder::getStructIndex(Element& type, Element& field) {
Expression* SExpressionWasmBuilder::makeStructGet(Element& s, bool signed_) {
auto heapType = parseHeapType(*s[1]);
+ if (!heapType.isStruct()) {
+ throw ParseException("bad struct heap type", s.line, s.col);
+ }
auto index = getStructIndex(*s[1], *s[2]);
auto type = heapType.getStruct().fields[index].type;
auto ref = parseExpression(*s[3]);
@@ -2637,6 +2640,9 @@ Expression* SExpressionWasmBuilder::makeStructGet(Element& s, bool signed_) {
Expression* SExpressionWasmBuilder::makeStructSet(Element& s) {
auto heapType = parseHeapType(*s[1]);
+ if (!heapType.isStruct()) {
+ throw ParseException("bad struct heap type", s.line, s.col);
+ }
auto index = getStructIndex(*s[1], *s[2]);
auto ref = parseExpression(*s[3]);
validateHeapTypeUsingChild(ref, heapType, s);