rustwasm/twiggy

wasm files must have `.wasm` extension.

Badel2 opened this issue ยท 5 comments

๐Ÿ› Bug Description

twiggy fails to detect wasm files when they don't have a .wasm extension.

twiggy version: twiggy-opt 0.3.0

๐ŸŒ Test Case

Any file works, for example this one (5MB).

๐Ÿ‘Ÿ Steps to Reproduce

$ twiggy top test_case
 Shallow Bytes โ”‚ Shallow % โ”‚ Item
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
             0 โ”Š     0.00% โ”Š ฮฃ [0 Total Rows]
$ mv test_case test_case.wasm
$ twitty top test_case.wasm
<expected output>

๐Ÿ˜ฒ Actual Behavior

File is not detected as wasm.

๐Ÿค” Expected Behavior

The file should be detected as wasm by looking at its contents, not by using the filename extension.

Thanks for filing a bug @Badel2! We have code to fallback to auto-detection of the input binary's type, but we don't have tests for it, and --therfore unsurprisingly-- it looks like that functionality is broken.

It looks like we mistakenly always try to do the generic-binary-with-DWARF path if there is no extension and the "dwarf" feature is enabled. Instead, we should try and sniff the kind of thing we are looking at, and if it is wasm, do the wasm path, and if not, do the generic-binary-with-DWARF path.

This could be a good first issue for a motivated contributor!

https://github.com/rustwasm/twiggy/blob/master/parser/parser.rs#L39-L47

Some more details:

Since we use object for non-wasm binaries, I think we can simply check for the wasm magic number ourselves, and then defer any other case to object (and goblin, which it uses).

I want to try ! @fitzgen

@sepiropht ok! Contributing docs are over here: https://github.com/rustwasm/twiggy/blob/master/CONTRIBUTING.md Let me know if you have any questions :)