Skip to content

Conversation

@khagankhan
Copy link
Contributor

  • Add integration of mutatis wit fuzzer
  • remove serialize/deserialize for config instead use u64
  • use serialize/deserialize for fuzz_mutate

@khagankhan khagankhan requested review from a team as code owners July 21, 2025 16:56
@khagankhan khagankhan requested review from fitzgen and removed request for a team July 21, 2025 16:56
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.

Looks good, but there are a handful of small things to address before we merge this. Thanks!

Comment on lines 1335 to 1350
/// Fuzz target for table operations that reconstructs config from seed.
pub fn fuzz_table_ops((config_seed, ops): (u64, generators::table_ops::TableOps)) {
let mut buf = [0u8; 1024];
let mut rng = rand::rngs::StdRng::seed_from_u64(config_seed);

for b in buf.iter_mut() {
*b = rng.r#gen()
}

let u = Unstructured::new(&buf);
let config = generators::Config::arbitrary_take_rest(u)
.expect("should be able to generate config from seed");

let _ = crate::oracles::table_ops(config, ops);
}

Copy link
Member

Choose a reason for hiding this comment

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

We already have an oracle for fuzzing table ops, which is what this function is ultimately calling. This is really just a small adapter for when we need to use Arbitrary to generate a config, and it feels out of place here. The only place we need to actually do that is in the fuzz target itself, so lets just inline it into the fuzz_target! invocation in fuzz/fuzz_targets/table_ops.rs.

Choose a reason for hiding this comment

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

Yea makes sense! I guess I just updated the previous function which was in this file

fuzz/Cargo.toml Outdated

[dependencies]
mutatis = { workspace = true }
bincode = "2.0.1"
Copy link
Member

Choose a reason for hiding this comment

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

We should use postcard instead of bincode here, because we already depend on it in the workspace and don't need to worry about auditing or anything.

Suggested change
bincode = "2.0.1"
postcard = { workspace = true }

Comment on lines 22 to 23
bincode::decode_from_slice::<(u64, TableOps), _>(data, bincode::config::standard())
.map_or_else(|_err| (0, TableOps::default()), |(tuple, _)| tuple);
Copy link
Member

Choose a reason for hiding this comment

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

Slight simplification:

Suggested change
bincode::decode_from_slice::<(u64, TableOps), _>(data, bincode::config::standard())
.map_or_else(|_err| (0, TableOps::default()), |(tuple, _)| tuple);
bincode::decode_from_slice::<(u64, TableOps), _>(data, bincode::config::standard())
.ok()
.unwrap_or_default();

Choose a reason for hiding this comment

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

This is nice!

Comment on lines 186 to 192
/// Pops from the vector of the opcodes and returns bool
pub fn pop(&mut self) -> bool {
self.ops.pop().is_some()
}
Copy link
Member

Choose a reason for hiding this comment

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

Nitpicks:

  • Newline between methods, as elsewhere in the file
  • "returns bool" is not very descriptive, the doc comment should describe what the boolean result means.

Choose a reason for hiding this comment

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

I just wanted it to pass the clippy haha. Thanks!

wasmtime-test-util = { workspace = true, features = ['wast'] }

[dependencies]
bincode = "2.0.1"
Copy link
Member

Choose a reason for hiding this comment

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

postcard here too:

Suggested change
bincode = "2.0.1"
postcard = { workspace = true }

@khagan-karimov
Copy link

Thanks! Working on them!

@github-actions github-actions bot added the fuzzing Issues related to our fuzzing infrastructure label Jul 21, 2025
@github-actions
Copy link

Subscribe to Label Action

cc @fitzgen

This issue or pull request has been labeled: "fuzzing"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: fuzzing

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@khagankhan khagankhan force-pushed the integrate-gc-fuzzer branch from 07f2601 to 2a725fb Compare July 25, 2025 01:54
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.

Very close!

We should also remove table_ops from the misc fuzz target as part of this PR, as it will be redundant.

With the comment below addressed, this should be good to merge.

Thanks!

use wasmtime_fuzzing::generators::table_ops::TableOps;
use wasmtime_fuzzing::oracles::table_ops;

fuzz_target!(|input: (u64, TableOps)| {
Copy link
Member

Choose a reason for hiding this comment

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

We don't want the fuzz target to take structured types directly, as those get generated via Arbitrary, and we want to do our serialization- and mutation-based thing here.

Instead we should do something like this:

fuzz_target!(|data: &[u8]| {
    let Ok((seed, ops)) = postcard::from_bytes::<(u64, TableOps)>(data) else {
        return;
    }

    // As before: Make an RNG from the seed, fill the buf with random
    // data, make an `Unstructured`, call `Config::arbitrary_take_rest`,
    // and finally invoke `oracles::table_ops(config, ops)`.
});

Aside: once this PR lands, we should probably remove the Arbitrary implementation for TableOps as we won't be using it anymore and removing it will make usage footguns like this one disappear.

@khagankhan khagankhan force-pushed the integrate-gc-fuzzer branch from 2e0cfbf to b08fe60 Compare July 28, 2025 19:18
@fitzgen
Copy link
Member

fitzgen commented Jul 28, 2025

@khagankhan it looks like the Cargo.lock is still updating all dependencies. Do you have a tool that is doing that locally?

@khagankhan
Copy link
Contributor Author

I ran them locally and passed. Let us see!!

@khagankhan
Copy link
Contributor Author

@fitzgen Done ✅

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 added this pull request to the merge queue Jul 28, 2025
Merged via the queue into bytecodealliance:main with commit 6047d27 Jul 28, 2025
43 checks passed
@alexcrichton
Copy link
Member

Would it be possible to re-integrate the table_ops fuzzer back into the main "misc" fuzzer?

@fitzgen
Copy link
Member

fitzgen commented Jul 30, 2025

Unfortunately, we can't because it is using mutation-based fuzzing via mutatis now, not generative-based fuzzing via arbitrary. I think that's fine though because it is going to be gaining more GC-specific features and will start exploring new code paths now, rather than just the same paths it has been executing for a long time.

@alexcrichton
Copy link
Member

Sounds good to me 👍

bongjunj pushed a commit to prosyslab/wasmtime that referenced this pull request Oct 20, 2025
* Add fuzzer integration for gc/mutatis

* Replace bincode with postcard. Inline fuzz_mutate. Address other small comments

* Update Cargo.lock after rebase

* Update rng.gen to rng.fill to avoid deprecation failure

* Remove table_ops from misc. Update fuzz_target. Keep Arbitrary impl it gives some dependecy error. Will be addressed later

* Update Cargo.lock to match upstream/main

* Regenerate Cargo.lock after rebase and dependency changes

* Reset Cargo.lock to upstream/main to preserve cargo-deny compatibility

* Update dependencies

---------

Co-authored-by: Khagan Karimov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fuzzing Issues related to our fuzzing infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants