Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update all dependencies, wasmtime18, replace wasi-cap-std-sync with wasi-common #99

Merged
merged 6 commits into from
Mar 11, 2024

Conversation

Gentle
Copy link

@Gentle Gentle commented Mar 10, 2024

I've updated all dependencies and wasmtime to their latest versions

wasi-cap-std-sync was replaced with wasi-common, some code had to be adjusted

the tests are still green and it works in my test project

I haven't touched the fuzzing code yet, does anyone knwo how to run that so I can make sure it also survived the updates?

@Gentle
Copy link
Author

Gentle commented Mar 10, 2024

fuzzing is green again

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good to me modulo one thing below.

Comment on lines -188 to -228

#[derive(Clone, Default, Debug)]
struct WasmConfig;

impl<'a> arbitrary::Arbitrary<'a> for WasmConfig {
fn arbitrary(_: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(WasmConfig)
}
}

impl wasm_smith::Config for WasmConfig {
fn max_memories(&self) -> usize {
10
}

fn max_memory_pages(&self) -> u32 {
// We want small memories that are quick to compare, but we also want to
// allow memories to grow so we can shake out any memory-growth-related
// bugs, so we choose `2` instead of `1`.
2
}

fn min_funcs(&self) -> usize {
// Always generate at least one function that we can hopefully use as an
// initialization function.
1
}

fn min_exports(&self) -> usize {
// Always at least one export, hopefully a function we can use as an
// initialization routine.
1
}

fn memory_offset_choices(&self) -> (u32, u32, u32) {
// Always use an offset immediate that is within the memory's minimum
// size. This should make trapping on loads/stores a little less
// frequent.
(1, 0, 0)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to stop providing these configuration settings. The way that wasm-smith is configured has indeed changed a little though.

Instead of having the fuzz target take a wasm_smith::Module, we will want it to take the raw data from the fuzzer, manually construct an arbitrary::Unstructured from that data, make an arbitrary wasm_smith::Config with that Unstructured, and then apply the above settings to that config before generating a wasm_smith::Module. Something like this:

fuzz_target!(data: &[u8]) {
    let mut u = Unstructured::new(data);

    let mut config = wasm_smith::Config::arbitrary(&mut u)?;
    config.min_funcs = 1;
    // etc...

    let module = wasm_smith::Module::new(config, &mut u)?;

    // and then continue with the fuzz target as before...

});

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the fast reply, I applied your suggestion :)

Comment on lines 32 to 54
let mut config = wasm_smith::Config::arbitrary(&mut u).unwrap();
config.max_memories = 10;

// We want small memories that are quick to compare, but we also want to
// allow memories to grow so we can shake out any memory-growth-related
// bugs, so we choose `2` instead of `1`.
config.max_memory32_pages = 2;
config.max_memory64_pages = 2;

// Always generate at least one function that we can hopefully use as an
// initialization function.
config.min_funcs = 1;

// Always at least one export, hopefully a function we can use as an
// initialization routine.
config.min_exports = 1;

// Always use an offset immediate that is within the memory's minimum
// size. This should make trapping on loads/stores a little less
// frequent.
config.memory_offset_choices = MemoryOffsetChoices(1, 0, 0);

let mut module = wasm_smith::Module::new(config, &mut u).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try running the fuzz target by chance? I am pretty sure the unwrap on Module::new at least can fail at runtime. Not sure whether the Config one will in practice or not. The ensure_termination won't because we aren't enabling the feature in wasm-smith that causes it to return an error.

You can run the fuzz target locally to double check via

$ cargo fuzz run --sanitizer none same_result

In any case, I think we want to match on error results and simply early return, rather than panicking on error via unwrap.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so far I only ran the same command CI runs which is cargo fuzz build --dev -s none

is it intended that CI only builds this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it is a trade off because it isn't clear how long is "long enough" to run the fuzzers in CI and just building and linking them already takes a while in CI.

@Gentle
Copy link
Author

Gentle commented Mar 11, 2024

you were right, wasm_smith::Module::new needed a let-else return, now it goes much further :)

max_funcs and max_exports had to be added or else this assert fails

now it crashes after some minutes with

thread '<unnamed>' panicked at fuzz/fuzz_targets/same_result.rs:79:46:
called `Result::unwrap()` on an `Err` value: failed to parse WebAssembly module

Caused by:
    Unsupported feature: unsupported init expr in element section: GlobalGet { global_index: 0 }

which is at let module = wasmtime::Module::new(&engine, &wasm).unwrap();

should I also return on Err here?

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@fitzgen fitzgen merged commit 750c537 into bytecodealliance:main Mar 11, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants