You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reject out-of-range NaN payloads and bare type-index value types (#2563)
* wast: reject out-of-range NaN payloads
A NaN literal's payload `n` must satisfy `1 <= n < 2^signif_bits` (52 bits
for f64, 23 for f32). The parser masked the payload to the significand width
instead of range-checking it, so an over-long payload such as
`nan:0xffffffffffffff` (56 bits for f64) was silently truncated and accepted
rather than rejected as the reference interpreter does.
Range-check the payload against the significand width instead of masking.
The spec testsuite only exercised the power-of-two boundary `nan:0x80_0000`,
which the old masking rejected by coincidence (it masks to 0, hitting the
"payload is zero => infinity" check), so out-of-range payloads that mask to a
nonzero value went unnoticed. Regression tests cover both the invalid cases
and the adjacent valid boundaries.
* wasmparser: reject bare type index as a value type
The short form of a reference type (without a `0x63`/`0x64` prefix) is only an
abbreviation for `ref null <abstract-heap-type>`. The decoder instead parsed a
full heap type there, which additionally accepts a bare non-negative type
index, so `0x00` was wrongly decoded as the value type `(ref null 0)`.
Parse an abstract heap type directly in the short-form path (handling the
`0x65` prefix for `shared` variants) so a bare index is rejected at decode
time. This also covers the over-long-LEB variant (`ff 00`). In value-type
position the error surfaces as `invalid value type`; in a reference-type-only
position (e.g. a table element type) as `malformed reference type`. The
legitimate `0x63 <idx>` / `0x64 <idx>` concrete reftypes and the `shared`
abstract shorthands (`0x65 ...`) are unaffected.
0 commit comments