Skip to content

wasm-opt rejects valid module with invalid tag index on declared typed elem segments #8540

@jtenner

Description

@jtenner

Summary

Binaryen wasm-opt rejects a valid module with:

parse exception: invalid tag index (at 0:51)

This reproduces on both:

  • local wasm-opt version 125 (version_125)
  • current upstream release wasm-opt version 128 (version_128)

wasm-tools validate accepts the same module.

Minimal Repro

(module
  (rec
    (type (array i16))
    (type (sub (struct)))
    (type (array (mut nullexternref)))
    (type (sub (func (param i64))))
    (type (array (mut f32)))
    (type (sub (array (mut v128))))
  )
  (elem declare (ref null 2))
  (elem declare (ref null 3) (ref.null 3))
  (elem declare nullref)
  (func (type 3) (param i64))
  (func (type 3) (param i64))
)

Reproduction

cat > repro.wat <<'WAT'
(module
  (rec
    (type (array i16))
    (type (sub (struct)))
    (type (array (mut nullexternref)))
    (type (sub (func (param i64))))
    (type (array (mut f32)))
    (type (sub (array (mut v128))))
  )
  (elem declare (ref null 2))
  (elem declare (ref null 3) (ref.null 3))
  (elem declare nullref)
  (func (type 3) (param i64))
  (func (type 3) (param i64))
)
WAT

wasm-tools parse repro.wat -o repro.wasm
wasm-tools validate repro.wasm
wasm-opt repro.wasm --all-features -o out.wasm

Actual Result

[parse exception: invalid tag index (at 0:51)]
Fatal: error parsing wasm (try --debug for more info)

Expected Result

Binaryen should parse the module successfully, or reject it with a different validation/parsing error if the module is actually invalid under the enabled features.

Provenance

I hit this while differentially fuzzing remove-unused-names against Binaryen in Starshine, but the failure reproduces without any pass flags at all:

wasm-opt repro.wasm --all-features -o out.wasm

The original saved fuzz case is a valid module accepted by wasm-tools validate and replays as a pure Binaryen command failure rather than a semantic mismatch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions