|
1 | | -#![no_main] |
2 | | - |
3 | 1 | mod utils; |
4 | 2 |
|
5 | | -use libfuzzer_sys::fuzz_target; |
| 3 | +use arbitrary::Unstructured; |
| 4 | +use honggfuzz::fuzz; |
6 | 5 | use std::{collections::hash_map::RandomState, mem}; |
7 | | -use utils::{arbitrary_exec_module, ty_to_val}; |
| 6 | +use utils::arbitrary_config; |
8 | 7 | use wasmi as wasmi_reg; |
9 | 8 | use wasmi_reg::core::{F32, F64}; |
10 | 9 |
|
@@ -68,7 +67,15 @@ impl WasmiRegister { |
68 | 67 | } |
69 | 68 |
|
70 | 69 | fn type_to_value(ty: &wasmi_reg::core::ValType) -> wasmi_reg::Val { |
71 | | - ty_to_val(ty) |
| 70 | + match ty { |
| 71 | + wasmi_reg::core::ValType::I32 => wasmi_reg::Val::I32(1), |
| 72 | + wasmi_reg::core::ValType::I64 => wasmi_reg::Val::I64(1), |
| 73 | + wasmi_reg::core::ValType::F32 => wasmi_reg::Val::F32(1.0.into()), |
| 74 | + wasmi_reg::core::ValType::F64 => wasmi_reg::Val::F64(1.0.into()), |
| 75 | + unsupported => panic!( |
| 76 | + "differential fuzzing does not support reference types, yet but found: {unsupported:?}" |
| 77 | + ), |
| 78 | + } |
72 | 79 | } |
73 | 80 | } |
74 | 81 |
|
@@ -169,7 +176,7 @@ impl WasmiStack { |
169 | 176 | ValueType::F32 => wasmi_stack::Value::F32(1.0.into()), |
170 | 177 | ValueType::F64 => wasmi_stack::Value::F64(1.0.into()), |
171 | 178 | unsupported => panic!( |
172 | | - "execution fuzzing does not support reference types, yet but found: {unsupported:?}" |
| 179 | + "differential fuzzing does not support reference types, yet but found: {unsupported:?}" |
173 | 180 | ), |
174 | 181 | } |
175 | 182 | } |
@@ -254,7 +261,7 @@ impl Wasmtime { |
254 | 261 | wasmtime::ValType::F32 => wasmtime::Val::F32(1.0_f32.to_bits()), |
255 | 262 | wasmtime::ValType::F64 => wasmtime::Val::F64(1.0_f64.to_bits()), |
256 | 263 | unsupported => panic!( |
257 | | - "execution fuzzing does not support reference types, yet but found: {unsupported:?}" |
| 264 | + "differential fuzzing does not support reference types, yet but found: {unsupported:?}" |
258 | 265 | ), |
259 | 266 | } |
260 | 267 | } |
@@ -613,31 +620,44 @@ impl FuzzContext { |
613 | 620 | } |
614 | 621 | } |
615 | 622 |
|
616 | | -fuzz_target!(|data: &[u8]| { |
617 | | - let Ok(mut smith_module) = arbitrary_exec_module(data) else { |
618 | | - return; |
619 | | - }; |
620 | | - // Note: We cannot use built-in fuel metering of the different engines since that |
621 | | - // would introduce unwanted non-determinism with respect to fuzz testing. |
622 | | - let Ok(_) = smith_module.ensure_termination(1_000 /* fuel */) else { |
623 | | - return; |
624 | | - }; |
625 | | - let wasm = smith_module.to_bytes(); |
626 | | - let Some(wasmi_register) = <WasmiRegister as DifferentialTarget>::setup(&wasm[..]) else { |
627 | | - return; |
628 | | - }; |
629 | | - let Some(wasmi_stack) = <WasmiStack as DifferentialTarget>::setup(&wasm[..]) else { |
630 | | - panic!("wasmi (register) succeeded to create Context while wasmi (stack) failed"); |
631 | | - }; |
632 | | - let exports = wasmi_register.exports(); |
633 | | - let mut context = FuzzContext { |
634 | | - wasm, |
635 | | - wasmi_register, |
636 | | - wasmi_stack, |
637 | | - exports, |
638 | | - }; |
639 | | - context.run(); |
640 | | -}); |
| 623 | +fn main() { |
| 624 | + loop { |
| 625 | + fuzz!(|seed: &[u8]| { |
| 626 | + let mut unstructured = Unstructured::new(seed); |
| 627 | + let Ok(mut smith_module) = |
| 628 | + arbitrary_config(&mut unstructured).and_then(|mut config| { |
| 629 | + config.reference_types_enabled = false; |
| 630 | + config.tail_call_enabled = false; |
| 631 | + config.max_memories = 1; |
| 632 | + wasm_smith::Module::new(config, &mut unstructured) |
| 633 | + }) |
| 634 | + else { |
| 635 | + return; |
| 636 | + }; |
| 637 | + // Note: We cannot use built-in fuel metering of the different engines since that |
| 638 | + // would introduce unwanted non-determinism with respect to fuzz testing. |
| 639 | + let Ok(_) = smith_module.ensure_termination(1_000 /* fuel */) else { |
| 640 | + return; |
| 641 | + }; |
| 642 | + let wasm = smith_module.to_bytes(); |
| 643 | + let Some(wasmi_register) = <WasmiRegister as DifferentialTarget>::setup(&wasm[..]) |
| 644 | + else { |
| 645 | + return; |
| 646 | + }; |
| 647 | + let Some(wasmi_stack) = <WasmiStack as DifferentialTarget>::setup(&wasm[..]) else { |
| 648 | + panic!("wasmi (register) succeeded to create Context while wasmi (stack) failed"); |
| 649 | + }; |
| 650 | + let exports = wasmi_register.exports(); |
| 651 | + let mut context = FuzzContext { |
| 652 | + wasm, |
| 653 | + wasmi_register, |
| 654 | + wasmi_stack, |
| 655 | + exports, |
| 656 | + }; |
| 657 | + context.run(); |
| 658 | + }); |
| 659 | + } |
| 660 | +} |
641 | 661 |
|
642 | 662 | #[derive(Debug, Copy, Clone)] |
643 | 663 | pub enum FuzzValue { |
|
0 commit comments