-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from rust-secure-code/wasm
WASM support
- Loading branch information
Showing
28 changed files
with
807 additions
and
32 deletions.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "auditable-extract" | ||
version = "0.3.2" | ||
version = "0.3.3" | ||
authors = ["Sergey \"Shnatsel\" Davidoff <[email protected]>"] | ||
license = "MIT OR Apache-2.0" | ||
repository = "https://github.com/rust-secure-code/cargo-auditable" | ||
|
@@ -12,3 +12,7 @@ edition = "2018" | |
|
||
[dependencies] | ||
binfarce = "0.2" | ||
wasmparser = { version = "0.206.0", optional = true } | ||
|
||
[features] | ||
wasm = ["wasmparser"] |
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,4 @@ | ||
target | ||
corpus | ||
artifacts | ||
coverage |
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,30 @@ | ||
[package] | ||
name = "auditable-extract-fuzz" | ||
version = "0.0.0" | ||
publish = false | ||
edition = "2018" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
libfuzzer-sys = "0.4" | ||
|
||
[dependencies.auditable-extract] | ||
path = ".." | ||
features = ["wasm"] | ||
|
||
# Prevent this from interfering with workspaces | ||
[workspace] | ||
members = ["."] | ||
|
||
[profile.release] | ||
debug = 1 | ||
|
||
[[bin]] | ||
name = "parse_wasm" | ||
path = "fuzz_targets/parse_wasm.rs" | ||
test = false | ||
doc = false | ||
|
||
# The other format parsers are tested as part of the `binfarce` crate |
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,7 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let _ = auditable_extract::raw_auditable_data_wasm_for_fuzz(data); | ||
}); |
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,52 @@ | ||
//! Implements WASM parsing | ||
use crate::Error; | ||
|
||
use wasmparser::{self, Chunk, Payload}; | ||
|
||
pub(crate) fn raw_auditable_data_wasm(mut input: &[u8]) -> Result<&[u8], Error> { | ||
let mut parser = wasmparser::Parser::new(0); | ||
|
||
// `wasmparser` relies on manually advancing the offset, | ||
// which potentially allows infinite loops if the logic is wrong somewhere. | ||
// Therefore, limit the maximum number of iterations to 10,000. | ||
// This is way more than any sane WASM blob will have, | ||
// and prevents infinite loops in case of such logic errors. | ||
for _i in 0..10_000 { | ||
// wasmparser errors are strings, so we can't reasonably convert them | ||
let payload = match parser | ||
.parse(input, true) | ||
.map_err(|_| Error::MalformedFile)? | ||
{ | ||
// This shouldn't be possible because `eof` is always true. | ||
Chunk::NeedMoreData(_) => return Err(Error::MalformedFile), | ||
|
||
Chunk::Parsed { payload, consumed } => { | ||
// Guard against made-up "consumed" values that would cause a panic | ||
input = match input.get(consumed..) { | ||
Some(input) => input, | ||
None => return Err(Error::MalformedFile), | ||
}; | ||
payload | ||
} | ||
}; | ||
|
||
match payload { | ||
Payload::CustomSection(reader) => { | ||
if reader.name() == ".dep-v0" { | ||
return Ok(reader.data()); | ||
} | ||
} | ||
// We reached the end without seeing ".dep-v0" custom section | ||
Payload::End(_) => return Err(Error::NoAuditData), | ||
// ignore everything that's not a custom section | ||
_ => {} | ||
} | ||
} | ||
|
||
if cfg!(debug_assertions) { | ||
panic!("The parser has been running for more than 10k sections! Is it stuck?"); | ||
} else { | ||
Err(Error::MalformedFile) | ||
} | ||
} |
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
Oops, something went wrong.