|
5 | 5 | //! |
6 | 6 | //! This crate parses platform-specific binary formats ([ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format), |
7 | 7 | //! [PE](https://en.wikipedia.org/wiki/Portable_Executable), |
8 | | -//! [Mach-O](https://en.wikipedia.org/wiki/Mach-O)) and obtains the compressed audit data. |
| 8 | +//! [Mach-O](https://en.wikipedia.org/wiki/Mach-O), [WASM](https://en.wikipedia.org/wiki/WebAssembly)) and obtains the compressed audit data. |
9 | 9 | //! |
10 | 10 | //! Unlike other binary parsing crates, it is specifically designed to be resilient to malicious input. |
11 | 11 | //! It 100% safe Rust (including all dependencies) and performs no heap allocations. |
|
15 | 15 | //! **Note:** this is a low-level crate that only implements binary parsing. It rarely should be used directly. |
16 | 16 | //! You probably want the higher-level [`auditable-info`](https://docs.rs/auditable-info) crate instead. |
17 | 17 | //! |
18 | | -//! The following snippet demonstrates full extraction pipeline, including decompression |
| 18 | +//! The following snippet demonstrates full extraction pipeline using this crate, including decompression |
19 | 19 | //! using the safe-Rust [`miniz_oxide`](http://docs.rs/miniz_oxide/) and optional JSON parsing |
20 | 20 | //! via [`auditable-serde`](http://docs.rs/auditable-serde/): |
21 | 21 | //! |
|
42 | 42 | //! Ok(()) |
43 | 43 | //! } |
44 | 44 | //! ``` |
| 45 | +//! |
| 46 | +//! ## WebAssembly support |
| 47 | +//! |
| 48 | +//! We use a third-party crate [`wasmparser`](https://crates.io/crates/wasmparser) |
| 49 | +//! created by Bytecode Alliance for parsing WebAssembly. |
| 50 | +//! It is a robust and high-quality parser, but its dependencies contain some `unsafe` code, |
| 51 | +//! most of which is not actually used in our build configuration. |
| 52 | +//! |
| 53 | +//! We have manually audited it and found it to be sound. |
| 54 | +//! Still, the security guarantees for it are not as ironclad as for other parsers. |
| 55 | +//! Because of that WebAssembly support is gated behind the optional `wasm` feature. |
| 56 | +//! Be sure to [enable](https://doc.rust-lang.org/cargo/reference/features.html#dependency-features) |
| 57 | +//! the `wasm` feature if you want to parse WebAssembly. |
| 58 | +
|
| 59 | +#[cfg(feature = "wasm")] |
| 60 | +mod wasm; |
45 | 61 |
|
46 | 62 | use binfarce::Format; |
47 | 63 |
|
@@ -75,10 +91,22 @@ pub fn raw_auditable_data(data: &[u8]) -> Result<&[u8], Error> { |
75 | 91 | .ok_or(Error::NoAuditData)?; |
76 | 92 | Ok(data.get(section.range()?).ok_or(Error::UnexpectedEof)?) |
77 | 93 | } |
78 | | - _ => Err(Error::NotAnExecutable), |
| 94 | + Format::Unknown => { |
| 95 | + #[cfg(feature = "wasm")] |
| 96 | + if data.starts_with(b"\0asm") { |
| 97 | + return wasm::raw_auditable_data_wasm(data); |
| 98 | + } |
| 99 | + |
| 100 | + Err(Error::NotAnExecutable) |
| 101 | + } |
79 | 102 | } |
80 | 103 | } |
81 | 104 |
|
| 105 | +#[cfg(all(fuzzing, feature = "wasm"))] |
| 106 | +pub fn raw_auditable_data_wasm_for_fuzz(input: &[u8]) -> Result<&[u8], Error> { |
| 107 | + wasm::raw_auditable_data_wasm(input) |
| 108 | +} |
| 109 | + |
82 | 110 | #[derive(Debug, Copy, Clone)] |
83 | 111 | pub enum Error { |
84 | 112 | NoAuditData, |
|
0 commit comments