mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 08:13:27 +00:00
2a9fdf9aa1
* Misc Repo Cleanup Tasks * Dependency Trimming * Dep cleanup * Restrict libfuzzer * Flip cfg * mod fuzz
50 lines
1.4 KiB
Rust
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);
|
|
});
|
|
}
|