Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail deterministically on invalid modules #1969

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions src/bin/wasm-tools/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,31 @@ impl Opts {
}
log::info!("module structure validated in {:?}", start.elapsed());

// After we've validate the entire wasm module we'll use `rayon` to iterate
// over all functions in parallel and perform parallel validation of the
// input wasm module.
// After we've validate the entire wasm module we'll use `rayon` to
// iterate over all functions in parallel and perform parallel
// validation of the input wasm module.
//
// Note that validation results for each function are collected into a
// vector to ensure that in the case of multiple errors the first is
// always reported. Otherwise `rayon` does not guarantee the order that
// failures show up in.
let start = Instant::now();
functions_to_validate.into_par_iter().try_for_each_init(
FuncValidatorAllocations::default,
|allocs, (to_validate, body)| -> Result<_> {
let mut validator = to_validate.into_validator(mem::take(allocs));
validator
.validate(&body)
.with_context(|| format!("func {} failed to validate", validator.index()))?;
*allocs = validator.into_allocations();
Ok(())
},
)?;
functions_to_validate
.into_par_iter()
.map_init(
FuncValidatorAllocations::default,
|allocs, (to_validate, body)| -> Result<_> {
let mut validator = to_validate.into_validator(mem::take(allocs));
validator.validate(&body).with_context(|| {
format!("func {} failed to validate", validator.index())
})?;
*allocs = validator.into_allocations();
Ok(())
},
)
.collect::<Vec<_>>()
.into_iter()
.collect::<Result<Vec<_>>>()?;
log::info!("functions validated in {:?}", start.elapsed());
Ok(())
}
Expand Down
105 changes: 105 additions & 0 deletions tests/cli/multiple-failures.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
;; FAIL: validate %

(module
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
(func (result i32))
)
4 changes: 4 additions & 0 deletions tests/cli/multiple-failures.wat.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: func 0 failed to validate

Caused by:
0: type mismatch: expected i32 but nothing on stack (at offset 0x7d)
Loading