2021-11-14 02:00:34 -06:00
|
|
|
#![no_main]
|
|
|
|
use libfuzzer_sys::fuzz_target;
|
|
|
|
|
2022-11-29 12:05:43 -06:00
|
|
|
use waffle::{FrontendError, Module};
|
2021-11-14 02:00:34 -06:00
|
|
|
|
|
|
|
fuzz_target!(|module: wasm_smith::Module| {
|
|
|
|
let _ = env_logger::try_init();
|
2021-11-20 14:20:34 -06:00
|
|
|
log::debug!("original module: {:?}", module);
|
2021-11-14 02:00:34 -06:00
|
|
|
let orig_bytes = module.to_bytes();
|
2022-12-02 13:58:04 -06:00
|
|
|
let mut parsed_module = match Module::from_wasm_bytes(&orig_bytes[..]) {
|
2022-11-29 12:05:43 -06:00
|
|
|
Ok(m) => m,
|
|
|
|
Err(e) => {
|
|
|
|
match e.downcast::<FrontendError>() {
|
2022-11-29 12:36:45 -06:00
|
|
|
Ok(FrontendError::UnsupportedFeature(_)) | Ok(FrontendError::TooLarge(_)) => {
|
2022-11-29 12:05:43 -06:00
|
|
|
// Just skip this case.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Ok(e) => {
|
|
|
|
panic!("Frontend error: {:?}", e);
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
panic!("Other error when parsing module: {:?}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2023-02-07 16:34:59 -06:00
|
|
|
parsed_module.expand_all_funcs().unwrap();
|
2022-12-02 13:58:04 -06:00
|
|
|
parsed_module.optimize();
|
2021-11-14 02:00:34 -06:00
|
|
|
let _ = parsed_module.to_wasm_bytes();
|
|
|
|
});
|