Skip to content

Commit 5f240d1

Browse files
Honryrossberg
authored andcommitted
[test] More tests for non-minimal LEB128 (#1007)
1 parent ec592be commit 5f240d1

File tree

1 file changed

+144
-20
lines changed

1 file changed

+144
-20
lines changed

test/core/binary.wast

Lines changed: 144 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
;; Leading UTF-8 BOM.
3434
(assert_malformed (module binary "\ef\bb\bf\00asm\01\00\00\00") "magic header not detected")
3535

36+
;; Malformed binary version.
3637
(assert_malformed (module binary "\00asm") "unexpected end")
3738
(assert_malformed (module binary "\00asm\01") "unexpected end")
3839
(assert_malformed (module binary "\00asm\01\00\00") "unexpected end")
@@ -54,6 +55,149 @@
5455
"\05\07\01" ;; Memory section with 1 entry
5556
"\00\82\80\80\80\00" ;; no max, minimum 2
5657
)
58+
(module binary
59+
"\00asm" "\01\00\00\00"
60+
"\05\06\01" ;; Memory section with 1 entry
61+
"\01\82\00" ;; minimum 2
62+
"\82\00" ;; max 2
63+
)
64+
(module binary
65+
"\00asm" "\01\00\00\00"
66+
"\05\09\01" ;; Memory section with 1 entry
67+
"\01\82\00" ;; minimum 2
68+
"\82\80\80\80\00" ;; max 2
69+
)
70+
(module binary
71+
"\00asm" "\01\00\00\00"
72+
"\05\03\01" ;; Memory section with 1 entry
73+
"\00\00" ;; no max, minimum 0
74+
"\0b\07\01" ;; Data section with 1 entry
75+
"\80\00" ;; Memory index 0, encoded with 2 bytes
76+
"\41\00\0b\00" ;; (i32.const 0) with contents ""
77+
)
78+
(module binary
79+
"\00asm" "\01\00\00\00"
80+
"\04\04\01" ;; Table section with 1 entry
81+
"\70\00\00" ;; no max, minimum 0, funcref
82+
"\09\07\01" ;; Element section with 1 entry
83+
"\80\00" ;; Table index 0, encoded with 2 bytes
84+
"\41\00\0b\00" ;; (i32.const 0) with no elements
85+
)
86+
(module binary
87+
"\00asm" "\01\00\00\00"
88+
"\00" ;; custom section
89+
"\8a\00" ;; section size 10, encoded with 2 bytes
90+
"\01" ;; name byte count
91+
"1" ;; name
92+
"23456789" ;; sequence of bytes
93+
)
94+
(module binary
95+
"\00asm" "\01\00\00\00"
96+
"\00" ;; custom section
97+
"\0b" ;; section size
98+
"\88\00" ;; name byte count 8, encoded with 2 bytes
99+
"12345678" ;; name
100+
"9" ;; sequence of bytes
101+
)
102+
(module binary
103+
"\00asm" "\01\00\00\00"
104+
"\01\08\01" ;; type section
105+
"\60" ;; func type
106+
"\82\00" ;; num params 2, encoded with 2 bytes
107+
"\7f\7e" ;; param type
108+
"\01" ;; num results
109+
"\7f" ;; result type
110+
)
111+
(module binary
112+
"\00asm" "\01\00\00\00"
113+
"\01\08\01" ;; type section
114+
"\60" ;; func type
115+
"\02" ;; num params
116+
"\7f\7e" ;; param type
117+
"\81\00" ;; num results 1, encoded with 2 bytes
118+
"\7f" ;; result type
119+
)
120+
(module binary
121+
"\00asm" "\01\00\00\00"
122+
"\01\05\01" ;; type section
123+
"\60\01\7f\00" ;; function type
124+
"\02\17\01" ;; import section
125+
"\88\00" ;; module name length 8, encoded with 2 bytes
126+
"\73\70\65\63\74\65\73\74" ;; module name
127+
"\09" ;; entity name length
128+
"\70\72\69\6e\74\5f\69\33\32" ;; entity name
129+
"\00" ;; import kind
130+
"\00" ;; import signature index
131+
)
132+
(module binary
133+
"\00asm" "\01\00\00\00"
134+
"\01\05\01" ;; type section
135+
"\60\01\7f\00" ;; function type
136+
"\02\17\01" ;; import section
137+
"\08" ;; module name length
138+
"\73\70\65\63\74\65\73\74" ;; module name
139+
"\89\00" ;; entity name length 9, encoded with 2 bytes
140+
"\70\72\69\6e\74\5f\69\33\32" ;; entity name
141+
"\00" ;; import kind
142+
"\00" ;; import signature index
143+
)
144+
(module binary
145+
"\00asm" "\01\00\00\00"
146+
"\01\05\01" ;; type section
147+
"\60\01\7f\00" ;; function type
148+
"\02\17\01" ;; import section
149+
"\08" ;; module name length
150+
"\73\70\65\63\74\65\73\74" ;; module name
151+
"\09" ;; entity name length 9
152+
"\70\72\69\6e\74\5f\69\33\32" ;; entity name
153+
"\00" ;; import kind
154+
"\80\00" ;; import signature index, encoded with 2 bytes
155+
)
156+
(module binary
157+
"\00asm" "\01\00\00\00"
158+
"\01\04\01" ;; type section
159+
"\60\00\00" ;; function type
160+
"\03\03\01" ;; function section
161+
"\80\00" ;; function 0 signature index, encoded with 2 bytes
162+
"\0a\04\01" ;; code section
163+
"\02\00\0b" ;; function body
164+
)
165+
(module binary
166+
"\00asm" "\01\00\00\00"
167+
"\01\04\01" ;; type section
168+
"\60\00\00" ;; fun type
169+
"\03\02\01\00" ;; function section
170+
"\07\07\01" ;; export section
171+
"\82\00" ;; string length 2, encoded with 2 bytes
172+
"\66\31" ;; export name f1
173+
"\00" ;; export kind
174+
"\00" ;; export func index
175+
"\0a\04\01" ;; code section
176+
"\02\00\0b" ;; function body
177+
)
178+
(module binary
179+
"\00asm" "\01\00\00\00"
180+
"\01\04\01" ;; type section
181+
"\60\00\00" ;; fun type
182+
"\03\02\01\00" ;; function section
183+
"\07\07\01" ;; export section
184+
"\02" ;; string length 2
185+
"\66\31" ;; export name f1
186+
"\00" ;; export kind
187+
"\80\00" ;; export func index, encoded with 2 bytes
188+
"\0a\04\01" ;; code section
189+
"\02\00\0b" ;; function body
190+
)
191+
(module binary
192+
"\00asm" "\01\00\00\00"
193+
"\01\04\01" ;; type section
194+
"\60\00\00" ;; fun type
195+
"\03\02\01\00" ;; function section
196+
"\0a" ;; code section
197+
"\05" ;; section size
198+
"\81\00" ;; num functions, encoded with 2 bytes
199+
"\02\00\0b" ;; function body
200+
)
57201

58202
;; Signed LEB128 can have non-minimal length
59203
(module binary
@@ -114,26 +258,6 @@
114258
"\0b" ;; end
115259
)
116260

117-
;; Data segment memory index can have non-minimal length
118-
(module binary
119-
"\00asm" "\01\00\00\00"
120-
"\05\03\01" ;; Memory section with 1 entry
121-
"\00\00" ;; no max, minimum 0
122-
"\0b\07\01" ;; Data section with 1 entry
123-
"\80\00" ;; Memory index 0, encoded with 2 bytes
124-
"\41\00\0b\00" ;; (i32.const 0) with contents ""
125-
)
126-
127-
;; Element segment table index can have non-minimal length
128-
(module binary
129-
"\00asm" "\01\00\00\00"
130-
"\04\04\01" ;; Table section with 1 entry
131-
"\70\00\00" ;; no max, minimum 0, funcref
132-
"\09\07\01" ;; Element section with 1 entry
133-
"\80\00" ;; Table index 0, encoded with 2 bytes
134-
"\41\00\0b\00" ;; (i32.const 0) with no elements
135-
)
136-
137261
;; Unsigned LEB128 must not be overlong
138262
(assert_malformed
139263
(module binary

0 commit comments

Comments
 (0)