mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-25 02:12:13 +00:00
update wasm-parser dep; use it for validation
This commit is contained in:
parent
2ac7b6408c
commit
bda5b19098
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -2340,7 +2340,7 @@ dependencies = [
|
|||||||
"serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_bytes 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_bytes 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"wasmparser 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"wasmparser 0.29.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2382,6 +2382,11 @@ name = "wasmparser"
|
|||||||
version = "0.28.0"
|
version = "0.28.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasmparser"
|
||||||
|
version = "0.29.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "which"
|
name = "which"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
@ -2755,6 +2760,7 @@ dependencies = [
|
|||||||
"checksum wasmparser 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f46e666ecb4a406483a59a49f9d0c17f327e70da53a128eccddae2eadb95865c"
|
"checksum wasmparser 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f46e666ecb4a406483a59a49f9d0c17f327e70da53a128eccddae2eadb95865c"
|
||||||
"checksum wasmparser 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5e01c420bc7d36e778bd242e1167b079562ba8b34087122cc9057187026d060"
|
"checksum wasmparser 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5e01c420bc7d36e778bd242e1167b079562ba8b34087122cc9057187026d060"
|
||||||
"checksum wasmparser 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)" = "40f426b1929bd26517fb10702e2a8e520d1845c49567aa4d244f426f10b206c1"
|
"checksum wasmparser 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)" = "40f426b1929bd26517fb10702e2a8e520d1845c49567aa4d244f426f10b206c1"
|
||||||
|
"checksum wasmparser 0.29.2 (registry+https://github.com/rust-lang/crates.io-index)" = "981a8797cf89762e0233ec45fae731cb79a4dfaee12d9f0fe6cee01e4ac58d00"
|
||||||
"checksum which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b57acb10231b9493c8472b20cb57317d0679a49e0bdbee44b3b803a6473af164"
|
"checksum which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b57acb10231b9493c8472b20cb57317d0679a49e0bdbee44b3b803a6473af164"
|
||||||
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
||||||
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
|
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
|
||||||
|
@ -10,7 +10,7 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
nix = "0.12.0"
|
nix = "0.12.0"
|
||||||
page_size = "0.4.1"
|
page_size = "0.4.1"
|
||||||
wasmparser = "0.23.0"
|
wasmparser = "0.29.2"
|
||||||
parking_lot = "0.7.1"
|
parking_lot = "0.7.1"
|
||||||
lazy_static = "1.2.0"
|
lazy_static = "1.2.0"
|
||||||
indexmap = "1.0.2"
|
indexmap = "1.0.2"
|
||||||
|
@ -93,13 +93,18 @@ pub fn compile_with_config(
|
|||||||
/// WebAssembly specification. Returns `true` if validation
|
/// WebAssembly specification. Returns `true` if validation
|
||||||
/// succeeded, `false` if validation failed.
|
/// succeeded, `false` if validation failed.
|
||||||
pub fn validate(wasm: &[u8]) -> bool {
|
pub fn validate(wasm: &[u8]) -> bool {
|
||||||
|
validate_and_report_errors(wasm).is_ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The same as `validate` but with an Error message on failure
|
||||||
|
pub fn validate_and_report_errors(wasm: &[u8]) -> ::std::result::Result<(), String> {
|
||||||
use wasmparser::WasmDecoder;
|
use wasmparser::WasmDecoder;
|
||||||
let mut parser = wasmparser::ValidatingParser::new(wasm, None);
|
let mut parser = wasmparser::ValidatingParser::new(wasm, None);
|
||||||
loop {
|
loop {
|
||||||
let state = parser.read();
|
let state = parser.read();
|
||||||
match *state {
|
match *state {
|
||||||
wasmparser::ParserState::EndWasm => break true,
|
wasmparser::ParserState::EndWasm => break Ok(()),
|
||||||
wasmparser::ParserState::Error(_) => break false,
|
wasmparser::ParserState::Error(e) => break Err(format!("{}", e)),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ impl ModuleInfo {
|
|||||||
let len = reader.bytes_remaining();
|
let len = reader.bytes_remaining();
|
||||||
let bytes = reader.read_bytes(len)?;
|
let bytes = reader.read_bytes(len)?;
|
||||||
let data = bytes.to_vec();
|
let data = bytes.to_vec();
|
||||||
let name = String::from_utf8_lossy(name).to_string();
|
let name = name.to_string();
|
||||||
self.custom_sections.insert(name, data);
|
self.custom_sections.insert(name, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ use wasmer::webassembly::InstanceABI;
|
|||||||
use wasmer::*;
|
use wasmer::*;
|
||||||
use wasmer_emscripten;
|
use wasmer_emscripten;
|
||||||
use wasmer_runtime::cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH};
|
use wasmer_runtime::cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH};
|
||||||
use wasmer_runtime_core::backend::CompilerConfig;
|
use wasmer_runtime_core::{self, backend::CompilerConfig};
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
#[structopt(name = "wasmer", about = "Wasm execution runtime.")]
|
#[structopt(name = "wasmer", about = "Wasm execution runtime.")]
|
||||||
@ -270,15 +270,8 @@ fn validate_wasm(validate: Validate) -> Result<(), String> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
wabt::Module::read_binary(wasm_binary, &Default::default())
|
wasmer_runtime_core::validate_and_report_errors(&wasm_binary)
|
||||||
.map_err(|err| {
|
.map_err(|err| format!("Validation failed: {}", err))?;
|
||||||
format!(
|
|
||||||
"Failed to read \"{}\" as a WASM binary: {}",
|
|
||||||
wasm_path_as_str, err
|
|
||||||
)
|
|
||||||
})?
|
|
||||||
.validate()
|
|
||||||
.map_err(|err| format!("Failed to validate \"{}\": {}", wasm_path_as_str, err))?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user