Repository: bytecodealliance/wasm-tools (rust)

Issue:
GC types aren't gated behind `gc` wasmparser feature
Currently this validates:

```
$ cargo run validate <<< "(module (type (array i8)))"
```

but it should require `--features gc` to enable that.

cc @imikushin 

Pull request:
Add gc feature gate to validate
Fix #1048.

Patch:
diff --git a/crates/wasmparser/src/validator.rs b/crates/wasmparser/src/validator.rs
index 194adaca..6b89fae7 100644
--- a/crates/wasmparser/src/validator.rs
+++ b/crates/wasmparser/src/validator.rs
@@ -306,7 +306,7 @@ impl WasmFeatures {
                         if self.gc {
                             Ok(())
                         } else {
-                            Err("gc proposal is not enabled for this heap type")
+                            Err("heap types not supported without the gc feature")
                         }
                     }
                 }
diff --git a/crates/wasmparser/src/validator/core.rs b/crates/wasmparser/src/validator/core.rs
index 3bae5365..8b7de9d1 100644
--- a/crates/wasmparser/src/validator/core.rs
+++ b/crates/wasmparser/src/validator/core.rs
@@ -514,6 +514,12 @@ impl Module {
                 Type::Func(t)
             }
             crate::Type::Array(t) => {
+                if !features.gc {
+                    return Err(BinaryReaderError::new(
+                        "array indexed types not supported without the gc feature",
+                        offset,
+                    ));
+                }
                 match t.element_type {
                     crate::StorageType::I8 | crate::StorageType::I16 => {}
                     crate::StorageType::Val(value_type) => {
diff --git a/src/bin/wasm-tools/validate.rs b/src/bin/wasm-tools/validate.rs
index 76476f89..0020e5d7 100644
--- a/src/bin/wasm-tools/validate.rs
+++ b/src/bin/wasm-tools/validate.rs
@@ -111,6 +111,7 @@ fn parse_features(arg: &str) -> Result<WasmFeatures> {
         ("sign-extension", |f| &mut f.sign_extension),
         ("mutable-global", |f| &mut f.mutable_global),
         ("relaxed-simd", |f| &mut f.relaxed_simd),
+        ("gc", |f| &mut f.gc),
     ];
 
     for part in arg.split(',').map(|s| s.trim()).filter(|s| !s.is_empty()) {


Test patch:
diff --git a/tests/local/missing-features/reference-types/gc-indexed-types.wast b/tests/local/missing-features/reference-types/gc-indexed-types.wast
new file mode 100644
index 00000000..5e6d056f
--- /dev/null
+++ b/tests/local/missing-features/reference-types/gc-indexed-types.wast
@@ -0,0 +1,6 @@
+(assert_invalid
+  (module (type (array i32)))
+  "array indexed types not supported without the gc feature")
+(assert_invalid
+  (module (type (array i8)))
+  "array indexed types not supported without the gc feature")
diff --git a/tests/local/missing-features/reference-types/gc.wast b/tests/local/missing-features/reference-types/gc.wast
index 74a3e043..dd1e45ba 100644
--- a/tests/local/missing-features/reference-types/gc.wast
+++ b/tests/local/missing-features/reference-types/gc.wast
@@ -1,30 +1,30 @@
 (assert_invalid
   (module (type (func (param i31ref))))
-  "gc proposal is not enabled")
+  "heap types not supported without the gc feature")
 (assert_invalid
   (module (type (func (param anyref))))
-  "gc proposal is not enabled")
+  "heap types not supported without the gc feature")
 (assert_invalid
   (module (type (func (param (ref none)))))
-  "gc proposal is not enabled")
+  "heap types not supported without the gc feature")
 (assert_invalid
   (module (type (func (param (ref array)))))
-  "gc proposal is not enabled")
+  "heap types not supported without the gc feature")
 (assert_invalid
   (module (type (func (param (ref struct)))))
-  "gc proposal is not enabled")
+  "heap types not supported without the gc feature")
 (assert_invalid
   (module (type (func (param (ref eq)))))
-  "gc proposal is not enabled")
+  "heap types not supported without the gc feature")
 (assert_invalid
   (module (type (func (param (ref noextern)))))
-  "gc proposal is not enabled")
+  "heap types not supported without the gc feature")
 (assert_invalid
   (module (type (func (param (ref nofunc)))))
-  "gc proposal is not enabled")
+  "heap types not supported without the gc feature")
 (assert_invalid
   (module (func (local i31ref)))
-  "gc proposal is not enabled")
+  "heap types not supported without the gc feature")
 (assert_invalid
   (module (func (block (result i31ref) unreachable)))
-  "gc proposal is not enabled")
+  "heap types not supported without the gc feature")