diff --git a/projects/wasmer/Dockerfile b/projects/wasmer/Dockerfile index b4fe3af6f4ce..fb08a00157a3 100644 --- a/projects/wasmer/Dockerfile +++ b/projects/wasmer/Dockerfile @@ -24,5 +24,4 @@ RUN git clone --depth 1 https://github.com/wasmerio/wasmer wasmer WORKDIR wasmer -COPY *.rs fuzz/fuzz_targets/ COPY build.sh default.options $SRC/ diff --git a/projects/wasmer/deterministic.rs b/projects/wasmer/deterministic.rs deleted file mode 100644 index a300cc38b3b7..000000000000 --- a/projects/wasmer/deterministic.rs +++ /dev/null @@ -1,85 +0,0 @@ -/* -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -*/ -#![no_main] - -use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; -use wasm_smith::{Config, ConfiguredModule}; -use wasmer::{CompilerConfig, Engine, EngineBuilder, Module, Store}; -use wasmer_compiler_cranelift::Cranelift; -use wasmer_compiler_llvm::LLVM; -use wasmer_compiler_singlepass::Singlepass; - -#[derive(Arbitrary, Debug, Default, Copy, Clone)] -struct NoImportsConfig; -impl Config for NoImportsConfig { - fn max_imports(&self) -> usize { - 0 - } - fn max_memory_pages(&self) -> u32 { - // https://github.com/wasmerio/wasmer/issues/2187 - 65535 - } - fn allow_start_export(&self) -> bool { - false - } -} - -fn compile_and_compare(name: &str, engine: Engine, wasm: &[u8]) { - let store = Store::new(engine); - - // compile for first time - let module = Module::new(&store, wasm).unwrap(); - let first = module.serialize().unwrap(); - - // compile for second time - let module = Module::new(&store, wasm).unwrap(); - let second = module.serialize().unwrap(); - - if first != second { - panic!("non-deterministic compilation from {}", name); - } -} - -fuzz_target!(|module: ConfiguredModule| { - let wasm_bytes = module.to_bytes(); - - let mut compiler = Cranelift::default(); - compiler.canonicalize_nans(true); - compiler.enable_verifier(); - compile_and_compare( - "universal-cranelift", - EngineBuilder::new(compiler.clone()).engine(), - &wasm_bytes, - ); - - let mut compiler = LLVM::default(); - compiler.canonicalize_nans(true); - compiler.enable_verifier(); - compile_and_compare( - "universal-llvm", - EngineBuilder::new(compiler.clone()).engine(), - &wasm_bytes, - ); - - let compiler = Singlepass::default(); - compile_and_compare( - "universal-singlepass", - EngineBuilder::new(compiler.clone()).engine(), - &wasm_bytes, - ); -}); diff --git a/projects/wasmer/metering.rs b/projects/wasmer/metering.rs deleted file mode 100644 index b0e11ee72783..000000000000 --- a/projects/wasmer/metering.rs +++ /dev/null @@ -1,89 +0,0 @@ -/* -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -*/ -#![no_main] - -use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; -use std::sync::Arc; -use wasm_smith::{Config, ConfiguredModule}; -use wasmer::wasmparser::Operator; -use wasmer::{imports, CompilerConfig, Instance, Module, Store}; -use wasmer_compiler_cranelift::Cranelift; -use wasmer_middlewares::Metering; - -#[derive(Arbitrary, Debug, Default, Copy, Clone)] -struct NoImportsConfig; -impl Config for NoImportsConfig { - fn max_imports(&self) -> usize { - 0 - } - fn max_memory_pages(&self) -> u32 { - // https://github.com/wasmerio/wasmer/issues/2187 - 65535 - } - fn allow_start_export(&self) -> bool { - false - } -} - -#[derive(Arbitrary)] -struct WasmSmithModule(ConfiguredModule); -impl std::fmt::Debug for WasmSmithModule { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&wasmprinter::print_bytes(self.0.to_bytes()).unwrap()) - } -} - -fn cost(operator: &Operator) -> u64 { - match operator { - Operator::LocalGet { .. } | Operator::I32Const { .. } => 1, - Operator::I32Add { .. } => 2, - _ => 0, - } -} - -fuzz_target!(|module: WasmSmithModule| { - let wasm_bytes = module.0.to_bytes(); - - if let Ok(path) = std::env::var("DUMP_TESTCASE") { - use std::fs::File; - use std::io::Write; - let mut file = File::create(path).unwrap(); - file.write_all(&wasm_bytes).unwrap(); - return; - } - - let mut compiler = Cranelift::default(); - compiler.canonicalize_nans(true); - compiler.enable_verifier(); - let metering = Arc::new(Metering::new(10, cost)); - compiler.push_middleware(metering); - let mut store = Store::new(compiler); - let module = Module::new(&store, &wasm_bytes).unwrap(); - match Instance::new(&mut store, &module, &imports! {}) { - Ok(_) => {} - Err(e) => { - let error_message = format!("{}", e); - if error_message.starts_with("RuntimeError: ") - && error_message.contains("out of bounds") - { - return; - } - panic!("{}", e); - } - } -}); diff --git a/projects/wasmer/universal_cranelift.rs b/projects/wasmer/universal_cranelift.rs deleted file mode 100644 index 478cb43b45fe..000000000000 --- a/projects/wasmer/universal_cranelift.rs +++ /dev/null @@ -1,75 +0,0 @@ -/* -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -*/ -#![no_main] - -use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; -use wasm_smith::{Config, ConfiguredModule}; -use wasmer::{imports, CompilerConfig, Instance, Module, Store}; -use wasmer_compiler_cranelift::Cranelift; - -#[derive(Arbitrary, Debug, Default, Copy, Clone)] -struct NoImportsConfig; -impl Config for NoImportsConfig { - fn max_imports(&self) -> usize { - 0 - } - fn max_memory_pages(&self) -> u32 { - // https://github.com/wasmerio/wasmer/issues/2187 - 65535 - } - fn allow_start_export(&self) -> bool { - false - } -} -#[derive(Arbitrary)] -struct WasmSmithModule(ConfiguredModule); -impl std::fmt::Debug for WasmSmithModule { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&wasmprinter::print_bytes(self.0.to_bytes()).unwrap()) - } -} - -fuzz_target!(|module: WasmSmithModule| { - let wasm_bytes = module.0.to_bytes(); - - if let Ok(path) = std::env::var("DUMP_TESTCASE") { - use std::fs::File; - use std::io::Write; - let mut file = File::create(path).unwrap(); - file.write_all(&wasm_bytes).unwrap(); - return; - } - - let mut compiler = Cranelift::default(); - compiler.canonicalize_nans(true); - compiler.enable_verifier(); - let mut store = Store::new(compiler); - let module = Module::new(&store, &wasm_bytes).unwrap(); - match Instance::new(&mut store, &module, &imports! {}) { - Ok(_) => {} - Err(e) => { - let error_message = format!("{}", e); - if error_message.starts_with("RuntimeError: ") - && error_message.contains("out of bounds") - { - return; - } - panic!("{}", e); - } - } -}); diff --git a/projects/wasmer/universal_llvm.rs b/projects/wasmer/universal_llvm.rs deleted file mode 100644 index a7d76b784961..000000000000 --- a/projects/wasmer/universal_llvm.rs +++ /dev/null @@ -1,75 +0,0 @@ -/* -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -*/ -#![no_main] - -use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; -use wasm_smith::{Config, ConfiguredModule}; -use wasmer::{imports, CompilerConfig, Instance, Module, Store}; -use wasmer_compiler_llvm::LLVM; - -#[derive(Arbitrary, Debug, Default, Copy, Clone)] -struct NoImportsConfig; -impl Config for NoImportsConfig { - fn max_imports(&self) -> usize { - 0 - } - fn max_memory_pages(&self) -> u32 { - // https://github.com/wasmerio/wasmer/issues/2187 - 65535 - } - fn allow_start_export(&self) -> bool { - false - } -} -#[derive(Arbitrary)] -struct WasmSmithModule(ConfiguredModule); -impl std::fmt::Debug for WasmSmithModule { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&wasmprinter::print_bytes(self.0.to_bytes()).unwrap()) - } -} - -fuzz_target!(|module: WasmSmithModule| { - let wasm_bytes = module.0.to_bytes(); - - if let Ok(path) = std::env::var("DUMP_TESTCASE") { - use std::fs::File; - use std::io::Write; - let mut file = File::create(path).unwrap(); - file.write_all(&wasm_bytes).unwrap(); - return; - } - - let mut compiler = LLVM::default(); - compiler.canonicalize_nans(true); - compiler.enable_verifier(); - let mut store = Store::new(compiler); - let module = Module::new(&store, &wasm_bytes).unwrap(); - match Instance::new(&mut store, &module, &imports! {}) { - Ok(_) => {} - Err(e) => { - let error_message = format!("{}", e); - if error_message.starts_with("RuntimeError: ") - && error_message.contains("out of bounds") - { - return; - } - panic!("{}", e); - } - } -}); diff --git a/projects/wasmer/universal_singlepass.rs b/projects/wasmer/universal_singlepass.rs deleted file mode 100644 index 1587b941f0cd..000000000000 --- a/projects/wasmer/universal_singlepass.rs +++ /dev/null @@ -1,83 +0,0 @@ -/* -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -*/ -#![no_main] - -use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; -use wasm_smith::{Config, ConfiguredModule}; -use wasmer::{imports, Instance, Module, Store}; -use wasmer_compiler_singlepass::Singlepass; - -#[derive(Arbitrary, Debug, Default, Copy, Clone)] -struct NoImportsConfig; -impl Config for NoImportsConfig { - fn max_imports(&self) -> usize { - 0 - } - fn max_memory_pages(&self) -> u32 { - // https://github.com/wasmerio/wasmer/issues/2187 - 65535 - } - fn allow_start_export(&self) -> bool { - false - } -} -#[derive(Arbitrary)] -struct WasmSmithModule(ConfiguredModule); -impl std::fmt::Debug for WasmSmithModule { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&wasmprinter::print_bytes(self.0.to_bytes()).unwrap()) - } -} - -fuzz_target!(|module: WasmSmithModule| { - let wasm_bytes = module.0.to_bytes(); - - if let Ok(path) = std::env::var("DUMP_TESTCASE") { - use std::fs::File; - use std::io::Write; - let mut file = File::create(path).unwrap(); - file.write_all(&wasm_bytes).unwrap(); - return; - } - - let compiler = Singlepass::default(); - let mut store = Store::new(compiler); - let module = Module::new(&store, &wasm_bytes); - let module = match module { - Ok(m) => m, - Err(e) => { - let error_message = format!("{}", e); - if error_message.contains("Validation error: invalid result arity: func type returns multiple values") || error_message.contains("Validation error: blocks, loops, and ifs may only produce a resulttype when multi-value is not enabled") || error_message.contains("multi-value returns not yet implemented") { - return; - } - panic!("{}", e); - } - }; - match Instance::new(&mut store, &module, &imports! {}) { - Ok(_) => {} - Err(e) => { - let error_message = format!("{}", e); - if error_message.starts_with("RuntimeError: ") - && error_message.contains("out of bounds") - { - return; - } - panic!("{}", e); - } - } -});