From 56acee228d93d8ca36e40e4eb659e91d4a058f6f Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 4 Feb 2021 02:33:13 +0000 Subject: [GC] Do not crash on unreachable inputs to struct.get/set (#3542) If the reference is unreachable then we cannot find the heap type to print in the text format. Instead of crashing or emitting something invalid, print a block instead - the block contains the children so they are emitted, and as the instruction was unreachable anyhow, this has no noticeable effect. It also parallels what we do in the binary format - skip unreachable code. --- src/wasm/wasm-validator.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 6a1b72476..a9a69b244 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2296,6 +2296,14 @@ void FunctionValidator::visitStructGet(StructGet* curr) { shouldBeTrue(getModule()->features.hasGC(), curr, "struct.get requires gc to be enabled"); + if (curr->ref->type == Type::unreachable) { + return; + } + if (!shouldBeTrue(curr->ref->type.isStruct(), + curr->ref, + "struct.get ref must be a struct")) { + return; + } const auto& fields = curr->ref->type.getHeapType().getStruct().fields; shouldBeTrue(curr->index < fields.size(), curr, "bad struct.get field"); auto field = fields[curr->index]; @@ -2315,6 +2323,14 @@ void FunctionValidator::visitStructSet(StructSet* curr) { shouldBeTrue(getModule()->features.hasGC(), curr, "struct.set requires gc to be enabled"); + if (curr->ref->type == Type::unreachable) { + return; + } + if (!shouldBeTrue(curr->ref->type.isStruct(), + curr->ref, + "struct.set ref must be a struct")) { + return; + } if (curr->ref->type != Type::unreachable) { const auto& fields = curr->ref->type.getHeapType().getStruct().fields; shouldBeTrue(curr->index < fields.size(), curr, "bad struct.get field"); -- cgit v1.2.3