diff --git a/Cargo.lock b/Cargo.lock index ce77be8677..751b5d39ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3262,9 +3262,9 @@ dependencies = [ [[package]] name = "wasm-mutate" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a3f74c801ac9b17a797d7d2ea441277bc1ded7ba521ca5146258d6510cc2f11" +checksum = "a0e9666b36c1e7e88bf1e0d114c8a4fe7d4e32d3aa38c1e8e9d71a972b99764a" dependencies = [ "egg", "log", @@ -3276,9 +3276,9 @@ dependencies = [ [[package]] name = "wasm-smith" -version = "0.11.9" +version = "0.11.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca488f460a34d3af30f1d65f26f108612f2755872f2aba9906c36f1c046ef1cf" +checksum = "e6ca3f5a24b691771929ac6adf330972e8ecbfe48dcf8809d7bf83216c124cfd" dependencies = [ "arbitrary", "flagset", @@ -3328,9 +3328,9 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.95.0" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ea896273ea99b15132414be1da01ab0d8836415083298ecaffbe308eaac87a" +checksum = "adde01ade41ab9a5d10ec8ed0bb954238cf8625b5cd5a13093d6de2ad9c2be1a" dependencies = [ "indexmap", "url", @@ -3347,9 +3347,9 @@ dependencies = [ [[package]] name = "wasmprinter" -version = "0.2.44" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae24500f9cc27a4b2b338e66693ff53c08b17cf920bdc81e402a09fe7a204eea" +checksum = "3045e1aa2cac847f4f94a1e25db9f084a947aeff47d9099fb9c5ccd16d335040" dependencies = [ "anyhow", "wasmparser", diff --git a/Cargo.toml b/Cargo.toml index 45d9031efd..20f37ce917 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -156,13 +156,13 @@ winch-codegen = { path = "winch/codegen", version = "=0.3.0" } target-lexicon = { version = "0.12.3", default-features = false, features = ["std"] } anyhow = "1.0.22" -wasmparser = "0.95.0" +wasmparser = "0.96.0" wat = "1.0.52" wast = "50.0.0" -wasmprinter = "0.2.44" +wasmprinter = "0.2.45" wasm-encoder = "0.20.0" -wasm-smith = "0.11.9" -wasm-mutate = "0.2.12" +wasm-smith = "0.11.10" +wasm-mutate = "0.2.13" wit-parser = "0.3" windows-sys = "0.42.0" env_logger = "0.9" diff --git a/cranelift/wasm/src/func_translator.rs b/cranelift/wasm/src/func_translator.rs index 43c3b2d760..17d8f33b3b 100644 --- a/cranelift/wasm/src/func_translator.rs +++ b/cranelift/wasm/src/func_translator.rs @@ -170,7 +170,7 @@ fn parse_local_decls( builder.set_srcloc(cur_srcloc(reader)); let pos = reader.original_position(); let count = reader.read_var_u32()?; - let ty = reader.read_val_type()?; + let ty = reader.read()?; validator.define_locals(pos, count, ty)?; declare_locals(builder, count, ty, &mut next_local, environ)?; } diff --git a/cranelift/wasm/src/module_translator.rs b/cranelift/wasm/src/module_translator.rs index 356c738e5f..6da7d0b5b0 100644 --- a/cranelift/wasm/src/module_translator.rs +++ b/cranelift/wasm/src/module_translator.rs @@ -108,9 +108,8 @@ pub fn translate_module<'data>( } Payload::CustomSection(s) if s.name() == "name" => { - let result = NameSectionReader::new(s.data(), s.data_offset()) - .map_err(|e| e.into()) - .and_then(|s| parse_name_section(s, environ)); + let result = + parse_name_section(NameSectionReader::new(s.data(), s.data_offset()), environ); if let Err(e) = result { log::warn!("failed to parse name section {:?}", e); } diff --git a/cranelift/wasm/src/sections_translator.rs b/cranelift/wasm/src/sections_translator.rs index 3030054d0b..ee06acb638 100644 --- a/cranelift/wasm/src/sections_translator.rs +++ b/cranelift/wasm/src/sections_translator.rs @@ -13,14 +13,12 @@ use crate::{ DataIndex, ElemIndex, FuncIndex, Global, GlobalIndex, GlobalInit, Memory, MemoryIndex, Table, TableIndex, Tag, TagIndex, TypeIndex, WasmError, WasmResult, }; -use core::convert::TryFrom; -use core::convert::TryInto; use cranelift_entity::packed_option::ReservedValue; use cranelift_entity::EntityRef; use std::boxed::Box; use std::vec::Vec; use wasmparser::{ - self, Data, DataKind, DataSectionReader, Element, ElementItem, ElementItems, ElementKind, + self, Data, DataKind, DataSectionReader, Element, ElementItems, ElementKind, ElementSectionReader, Export, ExportSectionReader, ExternalKind, FunctionSectionReader, GlobalSectionReader, GlobalType, ImportSectionReader, MemorySectionReader, MemoryType, NameSectionReader, Naming, Operator, TableSectionReader, TableType, TagSectionReader, TagType, @@ -65,7 +63,7 @@ pub fn parse_type_section<'a>( types: TypeSectionReader<'a>, environ: &mut dyn ModuleEnvironment<'a>, ) -> WasmResult<()> { - let count = types.get_count(); + let count = types.count(); environ.reserve_types(count)?; for entry in types { @@ -83,7 +81,7 @@ pub fn parse_import_section<'data>( imports: ImportSectionReader<'data>, environ: &mut dyn ModuleEnvironment<'data>, ) -> WasmResult<()> { - environ.reserve_imports(imports.get_count())?; + environ.reserve_imports(imports.count())?; for entry in imports { let import = entry?; @@ -121,7 +119,7 @@ pub fn parse_function_section( functions: FunctionSectionReader, environ: &mut dyn ModuleEnvironment, ) -> WasmResult<()> { - let num_functions = functions.get_count(); + let num_functions = functions.count(); if num_functions == std::u32::MAX { // We reserve `u32::MAX` for our own use in cranelift-entity. return Err(WasmError::ImplLimitExceeded); @@ -142,7 +140,7 @@ pub fn parse_table_section( tables: TableSectionReader, environ: &mut dyn ModuleEnvironment, ) -> WasmResult<()> { - environ.reserve_tables(tables.get_count())?; + environ.reserve_tables(tables.count())?; for entry in tables { let ty = table(entry?)?; @@ -157,7 +155,7 @@ pub fn parse_memory_section( memories: MemorySectionReader, environ: &mut dyn ModuleEnvironment, ) -> WasmResult<()> { - environ.reserve_memories(memories.get_count())?; + environ.reserve_memories(memories.count())?; for entry in memories { let memory = memory(entry?); @@ -172,7 +170,7 @@ pub fn parse_tag_section( tags: TagSectionReader, environ: &mut dyn ModuleEnvironment, ) -> WasmResult<()> { - environ.reserve_tags(tags.get_count())?; + environ.reserve_tags(tags.count())?; for entry in tags { let tag = tag(entry?); @@ -187,7 +185,7 @@ pub fn parse_global_section( globals: GlobalSectionReader, environ: &mut dyn ModuleEnvironment, ) -> WasmResult<()> { - environ.reserve_globals(globals.get_count())?; + environ.reserve_globals(globals.count())?; for entry in globals { let wasmparser::Global { ty, init_expr } = entry?; @@ -226,7 +224,7 @@ pub fn parse_export_section<'data>( exports: ExportSectionReader<'data>, environ: &mut dyn ModuleEnvironment<'data>, ) -> WasmResult<()> { - environ.reserve_exports(exports.get_count())?; + environ.reserve_exports(exports.count())?; for entry in exports { let Export { @@ -259,23 +257,28 @@ pub fn parse_start_section(index: u32, environ: &mut dyn ModuleEnvironment) -> W } fn read_elems(items: &ElementItems) -> WasmResult> { - let items_reader = items.get_items_reader()?; - let mut elems = Vec::with_capacity(usize::try_from(items_reader.get_count()).unwrap()); - for item in items_reader { - let elem = match item? { - ElementItem::Expr(init) => match init.get_binary_reader().read_operator()? { - Operator::RefNull { .. } => FuncIndex::reserved_value(), - Operator::RefFunc { function_index } => FuncIndex::from_u32(function_index), - s => { - return Err(WasmError::Unsupported(format!( - "unsupported init expr in element section: {:?}", - s - ))); - } - }, - ElementItem::Func(index) => FuncIndex::from_u32(index), - }; - elems.push(elem); + let mut elems = Vec::new(); + match items { + ElementItems::Functions(funcs) => { + for func in funcs.clone() { + elems.push(FuncIndex::from_u32(func?)); + } + } + ElementItems::Expressions(funcs) => { + for func in funcs.clone() { + let idx = match func?.get_binary_reader().read_operator()? { + Operator::RefNull { .. } => FuncIndex::reserved_value(), + Operator::RefFunc { function_index } => FuncIndex::from_u32(function_index), + s => { + return Err(WasmError::Unsupported(format!( + "unsupported init expr in element section: {:?}", + s + ))); + } + }; + elems.push(idx); + } + } } Ok(elems.into_boxed_slice()) } @@ -285,7 +288,7 @@ pub fn parse_element_section<'data>( elements: ElementSectionReader<'data>, environ: &mut dyn ModuleEnvironment, ) -> WasmResult<()> { - environ.reserve_table_elements(elements.get_count())?; + environ.reserve_table_elements(elements.count())?; for (index, entry) in elements.into_iter().enumerate() { let Element { @@ -337,7 +340,7 @@ pub fn parse_data_section<'data>( data: DataSectionReader<'data>, environ: &mut dyn ModuleEnvironment<'data>, ) -> WasmResult<()> { - environ.reserve_data_initializers(data.get_count())?; + environ.reserve_data_initializers(data.count())?; for (index, entry) in data.into_iter().enumerate() { let Data { diff --git a/crates/cranelift/src/compiler.rs b/crates/cranelift/src/compiler.rs index 3b5c8c9a37..1f3777aaf4 100644 --- a/crates/cranelift/src/compiler.rs +++ b/crates/cranelift/src/compiler.rs @@ -265,7 +265,12 @@ impl wasmtime_environ::Compiler for Compiler { context.func.stack_limit = Some(stack_limit); let FunctionBodyData { validator, body } = input; let mut validator = validator.into_validator(validator_allocations); - func_translator.translate_body(&mut validator, body, &mut context.func, &mut func_env)?; + func_translator.translate_body( + &mut validator, + body.clone(), + &mut context.func, + &mut func_env, + )?; let (_, code_buf) = compile_maybe_cached(&mut context, isa, cache_ctx.as_mut())?; // compile_maybe_cached returns the compiled_code but that borrow has the same lifetime as diff --git a/crates/environ/src/component/translate.rs b/crates/environ/src/component/translate.rs index 81483d0ba1..715ba2a2c7 100644 --- a/crates/environ/src/component/translate.rs +++ b/crates/environ/src/component/translate.rs @@ -618,8 +618,8 @@ impl<'a, 'data> Translator<'a, 'data> { } } - Payload::ComponentStartSection(s) => { - self.validator.component_start_section(&s)?; + Payload::ComponentStartSection { start, range } => { + self.validator.component_start_section(&start, &range)?; unimplemented!("component start section"); } diff --git a/crates/environ/src/module_environ.rs b/crates/environ/src/module_environ.rs index 4c578165a1..df289ff3fa 100644 --- a/crates/environ/src/module_environ.rs +++ b/crates/environ/src/module_environ.rs @@ -14,7 +14,7 @@ use std::convert::{TryFrom, TryInto}; use std::path::PathBuf; use std::sync::Arc; use wasmparser::{ - types::Types, CustomSectionReader, DataKind, ElementItem, ElementKind, Encoding, ExternalKind, + types::Types, CustomSectionReader, DataKind, ElementItems, ElementKind, Encoding, ExternalKind, FuncToValidate, FunctionBody, NameSectionReader, Naming, Operator, Parser, Payload, Type, TypeRef, Validator, ValidatorResources, }; @@ -232,7 +232,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { Payload::TypeSection(types) => { self.validator.type_section(&types)?; - let num = usize::try_from(types.get_count()).unwrap(); + let num = usize::try_from(types.count()).unwrap(); self.result.module.types.reserve(num); self.types.reserve_wasm_signatures(num); @@ -248,7 +248,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { Payload::ImportSection(imports) => { self.validator.import_section(&imports)?; - let cnt = usize::try_from(imports.get_count()).unwrap(); + let cnt = usize::try_from(imports.count()).unwrap(); self.result.module.initializers.reserve(cnt); for entry in imports { @@ -284,7 +284,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { Payload::FunctionSection(functions) => { self.validator.function_section(&functions)?; - let cnt = usize::try_from(functions.get_count()).unwrap(); + let cnt = usize::try_from(functions.count()).unwrap(); self.result.module.functions.reserve_exact(cnt); for entry in functions { @@ -297,7 +297,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { Payload::TableSection(tables) => { self.validator.table_section(&tables)?; - let cnt = usize::try_from(tables.get_count()).unwrap(); + let cnt = usize::try_from(tables.count()).unwrap(); self.result.module.table_plans.reserve_exact(cnt); for entry in tables { @@ -310,7 +310,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { Payload::MemorySection(memories) => { self.validator.memory_section(&memories)?; - let cnt = usize::try_from(memories.get_count()).unwrap(); + let cnt = usize::try_from(memories.count()).unwrap(); self.result.module.memory_plans.reserve_exact(cnt); for entry in memories { @@ -331,7 +331,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { Payload::GlobalSection(globals) => { self.validator.global_section(&globals)?; - let cnt = usize::try_from(globals.get_count()).unwrap(); + let cnt = usize::try_from(globals.count()).unwrap(); self.result.module.globals.reserve_exact(cnt); for entry in globals { @@ -369,7 +369,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { Payload::ExportSection(exports) => { self.validator.export_section(&exports)?; - let cnt = usize::try_from(exports.get_count()).unwrap(); + let cnt = usize::try_from(exports.count()).unwrap(); self.result.module.exports.reserve(cnt); for entry in exports { @@ -419,33 +419,36 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { // possible to create anything other than a `ref.null // extern` for externref segments, so those just get // translated to the reserved value of `FuncIndex`. - let items_reader = items.get_items_reader()?; - let mut elements = - Vec::with_capacity(usize::try_from(items_reader.get_count()).unwrap()); - for item in items_reader { - let func = match item? { - ElementItem::Func(f) => Some(f), - ElementItem::Expr(init) => { - match init.get_binary_reader().read_operator()? { - Operator::RefNull { .. } => None, - Operator::RefFunc { function_index } => Some(function_index), + let mut elements = Vec::new(); + match items { + ElementItems::Functions(funcs) => { + elements.reserve(usize::try_from(funcs.count()).unwrap()); + for func in funcs { + let func = FuncIndex::from_u32(func?); + self.flag_func_escaped(func); + elements.push(func); + } + } + ElementItems::Expressions(funcs) => { + elements.reserve(usize::try_from(funcs.count()).unwrap()); + for func in funcs { + let func = match func?.get_binary_reader().read_operator()? { + Operator::RefNull { .. } => FuncIndex::reserved_value(), + Operator::RefFunc { function_index } => { + let func = FuncIndex::from_u32(function_index); + self.flag_func_escaped(func); + func + } s => { return Err(WasmError::Unsupported(format!( "unsupported init expr in element section: {:?}", s ))); } - } + }; + elements.push(func); } - }; - elements.push(match func { - Some(f) => { - let f = FuncIndex::from_u32(f); - self.flag_func_escaped(f); - f - } - None => FuncIndex::reserved_value(), - }); + } } match kind { @@ -540,7 +543,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { _ => unreachable!(), }; - let cnt = usize::try_from(data.get_count()).unwrap(); + let cnt = usize::try_from(data.count()).unwrap(); initializers.reserve_exact(cnt); self.result.data.reserve_exact(cnt); @@ -620,9 +623,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { } Payload::CustomSection(s) if s.name() == "name" => { - let result = NameSectionReader::new(s.data(), s.data_offset()) - .map_err(|e| e.into()) - .and_then(|s| self.name_section(s)); + let result = self.name_section(NameSectionReader::new(s.data(), s.data_offset())); if let Err(e) = result { log::warn!("failed to parse name section {:?}", e); } diff --git a/crates/wasmtime/src/engine/serialization.rs b/crates/wasmtime/src/engine/serialization.rs index 8021b9ee2c..731e4d2c97 100644 --- a/crates/wasmtime/src/engine/serialization.rs +++ b/crates/wasmtime/src/engine/serialization.rs @@ -164,7 +164,6 @@ struct WasmFeatures { simd: bool, threads: bool, tail_call: bool, - deterministic_only: bool, multi_memory: bool, exceptions: bool, memory64: bool, @@ -183,7 +182,6 @@ impl Metadata { simd, threads, tail_call, - deterministic_only, multi_memory, exceptions, memory64, @@ -194,6 +192,7 @@ impl Metadata { mutable_global: _, saturating_float_to_int: _, sign_extension: _, + floats: _, } = engine.config().features; Metadata { @@ -209,7 +208,6 @@ impl Metadata { simd, threads, tail_call, - deterministic_only, multi_memory, exceptions, memory64, @@ -375,7 +373,6 @@ impl Metadata { simd, threads, tail_call, - deterministic_only, multi_memory, exceptions, memory64, @@ -406,11 +403,6 @@ impl Metadata { Self::check_bool(simd, other.simd, "WebAssembly SIMD support")?; Self::check_bool(threads, other.threads, "WebAssembly threads support")?; Self::check_bool(tail_call, other.tail_call, "WebAssembly tail-call support")?; - Self::check_bool( - deterministic_only, - other.deterministic_only, - "WebAssembly deterministic-only support", - )?; Self::check_bool( multi_memory, other.multi_memory, diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index caef1ae259..4e4d3a75b6 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -639,6 +639,12 @@ criteria = "safe-to-run" version = "0.2.12" notes = "The Bytecode Alliance is the author of this crate." +[[audits.wasm-mutate]] +who = "Alex Crichton " +criteria = "safe-to-run" +version = "0.2.13" +notes = "The Bytecode Alliance is the author of this crate." + [[audits.wasm-smith]] who = "Alex Crichton " criteria = "safe-to-deploy" @@ -687,6 +693,12 @@ criteria = "safe-to-run" version = "0.11.9" notes = "The Bytecode Alliance is the author of this crate." +[[audits.wasm-smith]] +who = "Alex Crichton " +criteria = "safe-to-run" +version = "0.11.10" +notes = "The Bytecode Alliance is the author of this crate." + [[audits.wasmi]] who = "Robin Freyler " criteria = "safe-to-run" @@ -783,6 +795,12 @@ criteria = "safe-to-deploy" version = "0.95.0" notes = "The Bytecode Alliance is the author of this crate." +[[audits.wasmparser]] +who = "Alex Crichton " +criteria = "safe-to-deploy" +version = "0.96.0" +notes = "The Bytecode Alliance is the author of this crate." + [[audits.wasmparser-nostd]] who = "Alex Crichton " criteria = "safe-to-run" @@ -842,6 +860,12 @@ criteria = "safe-to-deploy" version = "0.2.44" notes = "The Bytecode Alliance is the author of this crate." +[[audits.wasmprinter]] +who = "Alex Crichton " +criteria = "safe-to-deploy" +version = "0.2.45" +notes = "The Bytecode Alliance is the author of this crate." + [[audits.wast]] who = "Alex Crichton " criteria = "safe-to-deploy" diff --git a/winch/codegen/src/frame/mod.rs b/winch/codegen/src/frame/mod.rs index 737da3f846..4945809db2 100644 --- a/winch/codegen/src/frame/mod.rs +++ b/winch/codegen/src/frame/mod.rs @@ -128,7 +128,7 @@ impl Frame { for _ in 0..local_count { let position = reader.original_position(); let count = reader.read_var_u32()?; - let ty = reader.read_val_type()?; + let ty = reader.read()?; validator.define_locals(position, count, ty)?; let ty: ValType = ty.try_into()?;