use arbitrary::{Arbitrary, Unstructured}; use rand::{rngs::SmallRng, RngCore, SeedableRng}; use std::collections::HashMap; use wasm_smith::{Config, Module}; use wasmparser::Validator; use wasmparser::{Parser, TypeRef, ValType};
mod common; use common::{parser_features_from_config, validate};
for payload in Parser::new(0).parse_all(&wasm_bytes) { let payload = payload.unwrap(); iflet wasmparser::Payload::TypeSection(rdr) = payload { // Gather the signature types to later check function types // against. for ty in rdr.into_iter_err_on_gc_types() {
sig_types.push(ty.unwrap());
}
} elseiflet wasmparser::Payload::ImportSection(rdr) = payload { // Read out imports, checking that they all are within the // list of expected imports (i.e. we don't generate // arbitrary ones), and that we handle the logic correctly // (i.e. signature types are as expected) for import in rdr { let import = import.unwrap(); use AvailableImportKind as I; let entry = imports_seen.get_mut(&(import.module, import.name)); match (entry, &import.ty) {
(Some((true, _)), _) => panic!("duplicate import of {:?}", import),
(Some((seen, I::Memory)), TypeRef::Memory(_)) => *seen = true,
(Some((seen, I::Global(t))), TypeRef::Global(gt)) if *t == gt.content_type =>
{
*seen = true
}
(Some((seen, I::Table(t))), TypeRef::Table(tt)) if *t == ValType::Ref(tt.element_type) =>
{
*seen = true
}
(Some((seen, I::Func(p, r))), TypeRef::Func(sig_idx)) if sig_types[*sig_idx as usize].params() == *p
&& sig_types[*sig_idx as usize].results() == *r =>
{
*seen = true
}
(
Some((seen, I::Tag(p))),
TypeRef::Tag(wasmparser::TagType { func_type_idx, .. }),
) if sig_types[*func_type_idx as usize].params() == *p
&& sig_types[*func_type_idx as usize].results().is_empty() =>
{
*seen = true
}
(Some((_, expected)), _) => panic!( "import {:?} type mismatch, expected: {:?}",
import, expected
),
(None, _) => panic!("import of an unknown entity: {:?}", import),
}
}
}
}
// Verify that we have seen both instances with partial imports // (i.e. we don't always just copy over all the imports from the // example module) and also that we eventually observe all of the // imports being used (i.e. selection is reasonably random) for (m, f, _) in &available[..] { let seen = imports_seen[&(*m, *f)]; let global_seen = global_imports_seen
.entry((m.to_string(), f.to_string()))
.or_default();
*global_seen |= seen.0;
} if !imports_seen.values().all(|v| v.0) {
n_partial += 1;
}
}
}
assert!(global_imports_seen.values().all(|v| *v));
assert!(n_partial > 0);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.