Decodes a WebAssembly binary's sections into a wasm_module, refusing malformed ones
$ sexc add @ajax/wasm-decode- total 3
- drwxr-xr-x-../
- drwxr-xr-x-Oct 27 04:27v/# 1 version
- drwxr-xr-x-Oct 27 04:27files/# the files of 0.1.0
- latest
- 0.1.0, published Oct 27 04:27 by ajax
- owners
- ajax
- license
- MIT
- dependencies
- @ajax/wasm-module ^0.1.0, @ajax/wasm-instr ^0.1.0, @ajax/mesh-check ^0.1.0, @ajax/wasm-builder ^0.1.0
- dependents
- @ajax/wasm-float-guard, @ajax/wasm-fuse, @ajax/wasm-interp, @ajax/wasm-lower, @ajax/wasm-validate
- keywords
- wasm webassembly decoder parser
- repository
- https://github.com/thomasdavis/alpha-c-mesh
1# @ajax/wasm-decode 2 3Decodes a WebAssembly binary into a `wasm_module` (`@ajax/wasm-module`), checking everything the binary 4format requires: the header, section ids, order and exact sizes, custom sections' names, every vector 5and LEB, names' UTF-8, value types, limits flags (shared and 64-bit ones are recorded for the 6validator), element and data segment kinds, the function/code and data-count agreements, local counts 7(at most 50 000, as wasmparser), and well-formed constant expressions. Function bodies stay byte ranges 8for `@ajax/wasm-validate`. Counts are checked against the bytes left before anything is allocated, so a 9hostile binary never makes it allocate much or read out of bounds. Messages follow wasmparser's. 10 11Part of alpha-c-mesh's WebAssembly interpreter, which replaces wasmtime and wasmparser in the port of 12alpha-rust-mesh's `mesh-host/src/wasm.rs`. 13 14Tests: `tests/decode.c` (a module of every section kind, every truncation of it, and the malformed 15binaries the format forbids); fuzzing in `@ajax/wasm-interp`'s tests.