Skip to content

[interpreter] Binary decoder rejects heap type indices >= 2^31 as malformed #2289

Closed

Description

@kiranandcode

A heap type index is any non-negative s33:

grammar Bheaptype : heaptype =
| ht:Babsheaptype => ht
| x33:Bs33 => _IDX $s33_to_u32(x33) -- if x33 >= 0

So an index of 2^31 or 2^32 - 1 is well-formed, and a module using it is invalid (unknown type), not malformed. The decoder wraps the s33 to a signed 32-bit integer first and reports "integer representation too long":

let s33 s = Convert.I32_.wrap_i64 (sN 33 s)

;; (type (func (param (ref null 2147483648))))
(assert_invalid
  (module binary "\00asm" "\01\00\00\00"
    "\01\0a\01\60\01\63\80\80\80\80\08\00")
  "unknown type")

The interpreter fails this with integer representation too long. Index 2^31 - 1 (\ff\ff\ff\ff\07) is reported as "unknown type" as expected.

Tested at 340650f.

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