forked from gfx-rs/naga
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement fuzzing for the GLSL parser (gfx-rs#1301)
* Implement fuzzing for the GLSL parser * Remove arbitrary dependency from naga Derive `Arbitrary` for proxy objects in `fuzz/fuzz_targets/glsl_parser.rs` instead.
- Loading branch information
Hans Christian Schmitz
authored
Aug 31, 2021
1 parent
bd411c2
commit 2069ea6
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#![no_main] | ||
use arbitrary::Arbitrary; | ||
use libfuzzer_sys::fuzz_target; | ||
use naga::{ | ||
front::glsl::{Options, Parser}, | ||
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 = Parser::default(); | ||
let _result = parser.parse(&options.into(), &source); | ||
}); |