fuzz: updates fuzzing libs (#2138)

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
Takeshi Yoneda
2024-03-08 10:27:53 +09:00
committed by GitHub
parent 1e22783607
commit 60a670e3ce
5 changed files with 38 additions and 93 deletions

View File

@@ -3,16 +3,10 @@
version = 3
[[package]]
name = "ahash"
version = "0.8.6"
name = "anyhow"
version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a"
dependencies = [
"cfg-if",
"once_cell",
"version_check",
"zerocopy",
]
checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1"
[[package]]
name = "arbitrary"
@@ -23,17 +17,11 @@ dependencies = [
"derive_arbitrary",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
version = "1.3.2"
version = "2.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"
[[package]]
name = "cc"
@@ -50,6 +38,12 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cfg_aliases"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "ctor"
version = "0.2.6"
@@ -88,9 +82,6 @@ name = "hashbrown"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
dependencies = [
"ahash",
]
[[package]]
name = "indexmap"
@@ -119,9 +110,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.149"
version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libfuzzer-sys"
@@ -134,26 +125,16 @@ dependencies = [
"once_cell",
]
[[package]]
name = "memoffset"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
dependencies = [
"autocfg",
]
[[package]]
name = "nix"
version = "0.23.2"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c"
checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4"
dependencies = [
"bitflags",
"cc",
"cfg-if",
"cfg_aliases",
"libc",
"memoffset",
]
[[package]]
@@ -180,12 +161,6 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "semver"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "syn"
version = "1.0.98"
@@ -214,73 +189,37 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasm-encoder"
version = "0.37.0"
version = "0.201.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d135e8940b69dbee0f5b0a0be9c1cd6fa8b71d774904c13a3fcfc5dc265e43d"
checksum = "b9c7d2731df60006819b013f64ccc2019691deccf6e11a1804bc850cd6748f1a"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-smith"
version = "0.12.24"
version = "0.201.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d9a642a2aa8a998228a247036d0f34470a07afc146231bd5c22cc61b8b51e73"
checksum = "61ff53a54a853f174b0df74cdb1553f1451e7bcdc23b26b1379f664ee1913d1a"
dependencies = [
"anyhow",
"arbitrary",
"flagset",
"indexmap",
"leb128",
"wasm-encoder",
"wasmparser",
]
[[package]]
name = "wasmparser"
version = "0.117.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b206de0c992af9f0b51ef2fb9455623e0a19eb68f172cd8ba9cd0e46637f5ab"
dependencies = [
"hashbrown",
"indexmap",
"semver",
]
[[package]]
name = "wazero-fuzz-fuzz"
version = "0.0.0"
dependencies = [
"arbitrary",
"ctor",
"libc",
"libfuzzer-sys",
"nix",
"wasm-smith",
]
[[package]]
name = "zerocopy"
version = "0.7.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "306dca4455518f1f31635ec308b6b3e4eb1b11758cefafc782827d0aa7acb5c7"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be912bf68235a88fbefd1b73415cb218405958d1655b2ece9035a19920bdf6ba"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.40",
]

View File

@@ -10,10 +10,11 @@ cargo-fuzz = true
[dependencies]
libfuzzer-sys = "0.4.7"
wasm-smith = "0.12.20"
wasm-smith = "0.201.0"
libc = "0.2"
nix = "0.23.0"
nix = { version = "0.28.0" , features = ["signal"]}
ctor = "0.2.6"
arbitrary = "1.1.0"
[[bin]]
name = "memory_no_diff"

View File

@@ -14,13 +14,14 @@ extern "C" {
pub fn validate(binary_ptr: *const u8, binary_size: usize);
}
use arbitrary::Arbitrary;
use ctor::ctor;
use libc::SIGSTKSZ;
use libfuzzer_sys::arbitrary::Unstructured;
use nix::libc::{sigaltstack, stack_t};
use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal};
use std::ptr::null_mut;
use wasm_smith::SwarmConfig;
use wasm_smith::Config;
#[ctor]
/// Sets up the separate stack for signal handlers, and sets the SA_ONSTACK flag for signals that are handled by libFuzzer
@@ -92,7 +93,7 @@ pub fn run_nodiff(
let mut u = Unstructured::new(data);
// Generate the configuration.
let mut config: SwarmConfig = u.arbitrary()?;
let mut config = Config::arbitrary(&mut u)?;
// 64-bit memory won't be supported by wazero.
config.memory64_enabled = false;
@@ -100,7 +101,7 @@ pub fn run_nodiff(
config.max_memories = 1;
config.min_memories = 1;
// If we don't set the limit, we will soon reach the OOM and the fuzzing will be killed by OS.
config.max_memory_pages = 10;
config.max_memory32_pages = 10;
config.memory_max_size_required = true;
// Don't test too large tables.
config.max_tables = 2;
@@ -129,7 +130,7 @@ pub fn run_nodiff(
// Generate the random module via wasm-smith.
let mut module = wasm_smith::Module::new(config.clone(), &mut u)?;
module.ensure_termination(1000);
module.ensure_termination(1000).unwrap();
let module_bytes = module.to_bytes();
// Pass the randomly generated module to the wazero library.

View File

@@ -1,7 +1,9 @@
#![no_main]
use arbitrary::Arbitrary;
use libfuzzer_sys::arbitrary::{Result, Unstructured};
use libfuzzer_sys::fuzz_target;
use wasm_smith::Config;
mod util;
@@ -13,8 +15,11 @@ fn run(data: &[u8]) -> Result<()> {
// Create the random source.
let mut u = Unstructured::new(data);
// Generate the random module via wasm-smith, but MaybeInvalidModule.
let module: wasm_smith::MaybeInvalidModule = u.arbitrary()?;
// Generate the configuration with possibly invalid functions.
let mut config = Config::arbitrary(&mut u)?;
config.allow_invalid_funcs = true;
let module = wasm_smith::Module::new(config.clone(), &mut u)?;
let module_bytes = module.to_bytes();
unsafe {

View File

@@ -5,7 +5,6 @@ import (
"testing"
"github.com/tetratelabs/wazero/internal/testing/nodiff"
"github.com/tetratelabs/wazero/internal/testing/require"
)
// TestReRunFailedRequireNoDiffCase re-runs the failed case specified by WASM_BINARY_NAME in testdata directory.
@@ -17,5 +16,5 @@ func TestReRunFailedRequireNoDiffCase(t *testing.T) {
t.Skip(err)
}
nodiff.RequireNoDiff(wasmBin, true, true, func(err error) { require.NoError(t, err) })
nodiff.RequireNoDiffT(t, wasmBin, true, true)
}