|
| 1 | +;; RUN: wast --assert default --snapshot tests/snapshots % |
| 2 | + |
| 3 | +;; A value type is `numtype | vectype | reftype`, and a reference type is either |
| 4 | +;; an abstract heap type shorthand byte or the two-byte `0x64 heaptype` (`ref ht`) |
| 5 | +;; / `0x63 heaptype` (`ref null ht`) forms. There is no bare type-index value |
| 6 | +;; type, so a leading byte of `0x00` (a non-negative sLEB) is malformed. |
| 7 | + |
| 8 | +;; A bare index used as a value type. In value-type position the error is |
| 9 | +;; reclassified as "invalid value type". |
| 10 | +(assert_malformed |
| 11 | + (module binary |
| 12 | + "\00asm" "\01\00\00\00" ;; module header |
| 13 | + |
| 14 | + "\01\08\02" ;; type section, 2 types |
| 15 | + "\60\00\00" ;; type 0: (func) |
| 16 | + "\60\01" ;; type 1: (func (param ...)), 1 param |
| 17 | + "\00" ;; param 0: bare type index 0x00 (invalid value type) |
| 18 | + "\00" ;; 0 results |
| 19 | + ) |
| 20 | + "invalid value type") |
| 21 | + |
| 22 | +;; The same bug with an over-long LEB encoding of the bare index (`\ff\00` = 127). |
| 23 | +;; The reftype discriminator is a single byte, so this must be rejected at decode |
| 24 | +;; time rather than re-interpreted as a type index. |
| 25 | +(assert_malformed |
| 26 | + (module binary |
| 27 | + "\00asm" "\01\00\00\00" ;; module header |
| 28 | + |
| 29 | + "\01\09\02" ;; type section, 2 types |
| 30 | + "\60\00\00" ;; type 0: (func) |
| 31 | + "\60\01" ;; type 1: (func (param ...)), 1 param |
| 32 | + "\ff\00" ;; param 0: bare index 0x00 with an over-long LEB |
| 33 | + "\00" ;; 0 results |
| 34 | + ) |
| 35 | + "invalid value type") |
| 36 | + |
| 37 | +;; The same bare index in a reference-type-only position (a table's element type) |
| 38 | +;; is reported as a malformed reference type. |
| 39 | +(assert_malformed |
| 40 | + (module binary |
| 41 | + "\00asm" "\01\00\00\00" ;; module header |
| 42 | + |
| 43 | + "\04\04\01" ;; table section, 1 table |
| 44 | + "\00" ;; element type: bare index 0x00 (malformed reftype) |
| 45 | + "\00\00" ;; limits: no max, minimum 0 |
| 46 | + ) |
| 47 | + "malformed reference type") |
| 48 | + |
| 49 | +;; Boundary: the legitimate concrete reftypes `0x63 <idx>` (`ref null $t`) and |
| 50 | +;; `0x64 <idx>` (`ref $t`), where the index is an sLEB after the prefix byte, must |
| 51 | +;; still be accepted. |
| 52 | +(module binary |
| 53 | + "\00asm" "\01\00\00\00" ;; module header |
| 54 | + |
| 55 | + "\01\0b\02" ;; type section, 2 types |
| 56 | + "\60\00\00" ;; type 0: (func) |
| 57 | + "\60\02" ;; type 1: (func (param ...)), 2 params, 0 results |
| 58 | + "\63\00" ;; param 0: (ref null 0) |
| 59 | + "\64\00" ;; param 1: (ref 0) |
| 60 | + "\00" ;; 0 results |
| 61 | +) |
0 commit comments