|
| 1 | +;; Auxiliary modules to import |
| 2 | + |
| 3 | +(module |
| 4 | + (func (export "b") (result i32) (i32.const 0x0f)) |
| 5 | + (func (export "c") (result i32) (i32.const 0xf0)) |
| 6 | +) |
| 7 | +(register "a") |
| 8 | +(module |
| 9 | + (func (export "") (result i32) (i32.const 0xab)) |
| 10 | +) |
| 11 | +(register "") |
| 12 | + |
| 13 | + |
| 14 | +;; Valid compact encodings |
| 15 | + |
| 16 | +(module binary |
| 17 | + "\00asm" "\01\00\00\00" |
| 18 | + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) |
| 19 | + "\02\0e" ;; Import section |
| 20 | + "\01" ;; 1 group |
| 21 | + "\01a" ;; "a" |
| 22 | + "\00" "\7f" ;; "" + 0x7f (compact encoding) |
| 23 | + "\02" ;; 2 items |
| 24 | + "\01b" "\00\00" ;; "b" (func (type 0)) |
| 25 | + "\01c" "\00\00" ;; "c" (func (type 0)) |
| 26 | + "\03\02" "\01" ;; Function section, 1 func |
| 27 | + "\00" ;; func 2: type 0 |
| 28 | + "\07\08" "\01" ;; Export section, 1 export |
| 29 | + "\04test" "\00\02" ;; "test" func 2 |
| 30 | + "\0a\09" "\01" ;; Code section, 1 func |
| 31 | + "\07" "\00" ;; len, 0 locals |
| 32 | + "\10\00" ;; call 0 |
| 33 | + "\10\01" ;; call 1 |
| 34 | + "\6a" ;; i32.add |
| 35 | + "\0b" ;; end |
| 36 | +) |
| 37 | +(assert_return (invoke "test") (i32.const 0xff)) |
| 38 | + |
| 39 | +(module binary |
| 40 | + "\00asm" "\01\00\00\00" |
| 41 | + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) |
| 42 | + "\02\0c" ;; Import section |
| 43 | + "\01" ;; 1 group |
| 44 | + "\01a" ;; "a" |
| 45 | + "\00" "\7e" ;; "" + 0x7e (compact encoding) |
| 46 | + "\00\00" ;; (func (type 0)) |
| 47 | + "\02" ;; 2 items |
| 48 | + "\01b" ;; "b" |
| 49 | + "\01c" ;; "c" |
| 50 | + "\03\02" "\01" ;; Function section, 1 func |
| 51 | + "\00" ;; func 2: type 0 |
| 52 | + "\07\08" "\01" ;; Export section, 1 export |
| 53 | + "\04test" "\00\02" ;; "test" func 2 |
| 54 | + "\0a\09" "\01" ;; Code section, 1 func |
| 55 | + "\07" "\00" ;; len, 0 locals |
| 56 | + "\10\00" ;; call 0 |
| 57 | + "\10\01" ;; call 1 |
| 58 | + "\6a" ;; i32.add |
| 59 | + "\0b" ;; end |
| 60 | +) |
| 61 | +(assert_return (invoke "test") (i32.const 0xff)) |
| 62 | + |
| 63 | + |
| 64 | +;; Overly-long empty name encodings are valid |
| 65 | + |
| 66 | +(module binary |
| 67 | + "\00asm" "\01\00\00\00" |
| 68 | + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) |
| 69 | + "\02\11" ;; Import section |
| 70 | + "\01" ;; 1 group |
| 71 | + "\01a" ;; "a" |
| 72 | + "\80\80\80\00" "\7f" ;; "" (long encoding) + 0x7f |
| 73 | + "\02" ;; 2 items |
| 74 | + "\01b" "\00\00" ;; "b" (func (type 0)) |
| 75 | + "\01c" "\00\00" ;; "c" (func (type 0)) |
| 76 | +) |
| 77 | +(module binary |
| 78 | + "\00asm" "\01\00\00\00" |
| 79 | + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) |
| 80 | + "\02\0f" ;; Import section |
| 81 | + "\01" ;; 1 group |
| 82 | + "\01a" ;; "a" |
| 83 | + "\80\80\80\00" "\7e" ;; "" (long encoding) + 0x7e |
| 84 | + "\00\00" ;; (func (type 0)) |
| 85 | + "\02" ;; 2 items |
| 86 | + "\01b" ;; "b" |
| 87 | + "\01c" ;; "c" |
| 88 | +) |
| 89 | + |
| 90 | + |
| 91 | +;; Discriminator is not valid except after empty names |
| 92 | + |
| 93 | +(assert_malformed |
| 94 | + (module binary |
| 95 | + "\00asm" "\01\00\00\00" |
| 96 | + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) |
| 97 | + "\02\12" ;; Import section |
| 98 | + "\01" ;; 1 group |
| 99 | + "\01a" ;; "a" |
| 100 | + "\01b" "\7f" ;; "b" + 0x7f |
| 101 | + "\02" ;; 2 items |
| 102 | + "\01b" "\00\00" ;; "b" (func (type 0)) |
| 103 | + "\01c" "\00\00" ;; "c" (func (type 0)) |
| 104 | + ) |
| 105 | + "malformed import kind" |
| 106 | +) |
| 107 | +(assert_malformed |
| 108 | + (module binary |
| 109 | + "\00asm" "\01\00\00\00" |
| 110 | + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) |
| 111 | + "\02\10" ;; Import section |
| 112 | + "\01" ;; 1 group |
| 113 | + "\01a" ;; "a" |
| 114 | + "\01b" "\7e" ;; "" + 0x7e (long encoding) |
| 115 | + "\00\00" ;; (func (type 0)) |
| 116 | + "\02" ;; 2 items |
| 117 | + "\01b" ;; "b" |
| 118 | + "\01c" ;; "c" |
| 119 | + ) |
| 120 | + "malformed import kind" |
| 121 | +) |
| 122 | + |
| 123 | + |
| 124 | +;; Discriminator is not to be interpreted as LEB128 |
| 125 | + |
| 126 | +(assert_malformed |
| 127 | + (module binary |
| 128 | + "\00asm" "\01\00\00\00" |
| 129 | + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) |
| 130 | + "\02\11" ;; Import section |
| 131 | + "\01" ;; 1 group |
| 132 | + "\01a" ;; "a" |
| 133 | + "\00\ff\80\80\00" ;; "" + 0x7f (long encoding) |
| 134 | + "\02" ;; 2 items |
| 135 | + "\01b" "\00\00" ;; "b" (func (type 0)) |
| 136 | + "\01c" "\00\00" ;; "c" (func (type 0)) |
| 137 | + ) |
| 138 | + "malformed import kind" |
| 139 | +) |
| 140 | +(assert_malformed |
| 141 | + (module binary |
| 142 | + "\00asm" "\01\00\00\00" |
| 143 | + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) |
| 144 | + "\02\0f" ;; Import section |
| 145 | + "\01" ;; 1 group |
| 146 | + "\01a" ;; "a" |
| 147 | + "\00\fe\80\80\00" ;; "" + 0x7e (long encoding) |
| 148 | + "\00\00" ;; (func (type 0)) |
| 149 | + "\02" ;; 2 items |
| 150 | + "\01b" ;; "b" |
| 151 | + "\01c" ;; "c" |
| 152 | + ) |
| 153 | + "malformed import kind" |
| 154 | +) |
| 155 | + |
| 156 | + |
| 157 | +;; Empty names are still valid if not followed by a discriminator |
| 158 | + |
| 159 | +(module binary |
| 160 | + "\00asm" "\01\00\00\00" |
| 161 | + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) |
| 162 | + "\02\05" ;; Import section |
| 163 | + "\01" ;; 1 group |
| 164 | + "\00\00\00\00" ;; "" "" (func (type 0)) |
| 165 | + "\03\02" "\01" ;; Function section, 1 func |
| 166 | + "\00" ;; func 1: type 0 |
| 167 | + "\07\08" "\01" ;; Export section, 1 export |
| 168 | + "\04test" "\00\01" ;; "test" func 1 |
| 169 | + "\0a\06" "\01" ;; Code section, 1 func |
| 170 | + "\04" "\00" ;; len, 0 locals |
| 171 | + "\10\00" ;; call 0 |
| 172 | + "\0b" ;; end |
| 173 | +) |
| 174 | +(assert_return (invoke "test") (i32.const 0xab)) |
0 commit comments