Skip to content

Validator: catch_ref and catch_all_ref wrongly assume nullable exception type #189

Description

@simolus3

When a catch block is reached with an exception reference, it can be declared with a non-nullable (ref exn), e.g. this is a valid WebAssembly module:

(module
  (tag $my_error)
  (func $try_and_catch
    (block $handler (result (ref exn))
      (try_table (catch_ref $my_error $handler)
      )
      (return)
    )
    (drop)
  )
  (export "main" (func $try_and_catch))
)

wasm-tools validate agrees with this being valid, I used wasm-tools parse to turn it into a binary module. Attempting to load this module with endive fails:

Exception in thread "main" run.endive.wasm.InvalidException: type mismatch: instruction requires [ref[-23]] but stack has [refnull[-23]]
	at run.endive.wasm.Validator.validateFunction(Validator.java:2799)
	at run.endive.wasm.Validator.validateFunctions(Validator.java:906)
	at run.endive.wasm.WasmModule$Builder.build(WasmModule.java:289)
	at run.endive.wasm.Parser.parse(Parser.java:301)
	at run.endive.wasm.Parser.parse(Parser.java:262)
	at run.endive.wasm.Parser.parse(Parser.java:254)

The reason is that in validateFunction, validating a try_block pushes a ValType.ExnRef for CATCH_REF and CATCH_ALL_REF. exnref (aka (ref null exn) is not the same as (ref exn) though, which is what is required by the spec.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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