wgpu/naga/fuzz/fuzz_targets/glsl_parser.rs
Connor Fitzgerald 2a9fdf9aa1
Misc Repo Cleanup Tasks (#4579)
* Misc Repo Cleanup Tasks

* Dependency Trimming

* Dep cleanup

* Restrict libfuzzer

* Flip cfg

* mod fuzz
2023-10-27 00:15:51 -04:00

50 lines
1.4 KiB
Rust

#![no_main]
#[cfg(not(any(target_arch = "wasm32", target_os = "ios")))]
mod fuzz {
use arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;
use naga::{
front::glsl::{Frontend, Options},
FastHashMap, ShaderStage,
};
#[derive(Debug, Arbitrary)]
enum ShaderStageProxy {
Vertex,
Fragment,
Compute,
}
impl From<ShaderStageProxy> for ShaderStage {
fn from(proxy: ShaderStageProxy) -> Self {
match proxy {
ShaderStageProxy::Vertex => ShaderStage::Vertex,
ShaderStageProxy::Fragment => ShaderStage::Fragment,
ShaderStageProxy::Compute => ShaderStage::Compute,
}
}
}
#[derive(Debug, Arbitrary)]
struct OptionsProxy {
pub stage: ShaderStageProxy,
pub defines: FastHashMap<String, String>,
}
impl From<OptionsProxy> for Options {
fn from(proxy: OptionsProxy) -> Self {
Options {
stage: proxy.stage.into(),
defines: proxy.defines,
}
}
}
fuzz_target!(|data: (OptionsProxy, String)| {
let (options, source) = data;
// Ensure the parser can handle potentially malformed strings without crashing.
let mut parser = Frontend::default();
let _result = parser.parse(&options.into(), &source);
});
}