File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,6 +62,9 @@ impl Package {
6262 version : Option < & Version > ,
6363 bytes : Arc < Vec < u8 > > ,
6464 ) -> Result < Self > {
65+ if !has_magic_header ( & bytes) {
66+ bail ! ( "package `{name}` is expected to be a binary WebAssembly component binary but is not" ) ;
67+ }
6568 let mut parser = Parser :: new ( 0 ) ;
6669 let mut parsers = Vec :: new ( ) ;
6770 let mut validator = Validator :: new_with_features ( WasmFeatures {
@@ -182,6 +185,11 @@ impl Package {
182185 }
183186}
184187
188+ /// Whether the given bytes have a magic header indicating a WebAssembly binary.
189+ fn has_magic_header ( bytes : & [ u8 ] ) -> bool {
190+ bytes. starts_with ( b"\0 asm" )
191+ }
192+
185193impl fmt:: Debug for Package {
186194 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
187195 f. debug_struct ( "Package" )
Original file line number Diff line number Diff line change 11failed to resolve document
22
33 × failed to parse package `foo:bar`
4- ╰─▶ magic header not detected: bad magic number - expected=[
5- 0x0,
6- 0x61,
7- 0x73,
8- 0x6d,
9- ] actual=[
10- 0x74,
11- 0x68,
12- 0x69,
13- 0x73,
14- ] (at offset 0x0)
4+ ╰─▶ package `foo:bar` is expected to be a binary WebAssembly component binary but is not
155 ╭─[tests/resolution/fail/package-not-wasm.wac:3:13]
166 2 │
177 3 │ import foo: foo:bar/qux;
You can’t perform that action at this time.
0 commit comments