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:
- Wasm files begin with a "magic number" that can help sniffing: https://webassembly.github.io/spec/core/binary/modules.html#binary-magic
- As do ELF (https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header) and Mach-O (https://lowlevelbits.org/parsing-mach-o-files/ is quickest reference I can find).
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).
@sepiropht ok! Contributing docs are over here: https://github.com/rustwasm/twiggy/blob/master/CONTRIBUTING.md Let me know if you have any questions :)