Returns a count of the number of bytes within each stream shared with the parent input.
(
fuzzer: &Fuzzer,
input_id: usize,
extension_only: bool,
)
| 215 | |
| 216 | /// Returns a count of the number of bytes within each stream shared with the parent input. |
| 217 | pub fn count_parent_prefix( |
| 218 | fuzzer: &Fuzzer, |
| 219 | input_id: usize, |
| 220 | extension_only: bool, |
| 221 | ) -> HashMap<u64, usize> { |
| 222 | let input = &fuzzer.corpus[input_id]; |
| 223 | |
| 224 | if !input.metadata.stage.is_extension() && extension_only { |
| 225 | return HashMap::new(); |
| 226 | } |
| 227 | let Some(parent) = input.metadata.parent_id |
| 228 | else { |
| 229 | return HashMap::new(); |
| 230 | }; |
| 231 | let parent_data = &fuzzer.corpus[parent].data; |
| 232 | |
| 233 | let mut extensions = HashMap::new(); |
| 234 | for (addr, stream) in &input.data.streams { |
| 235 | let Some(parent_stream) = parent_data.streams.get(addr) |
| 236 | else { |
| 237 | continue; |
| 238 | }; |
| 239 | |
| 240 | let shared_prefix = |
| 241 | stream.bytes.iter().zip(&parent_stream.bytes).take_while(|(a, b)| a == b).count(); |
| 242 | extensions.insert(*addr, shared_prefix); |
| 243 | } |
| 244 | |
| 245 | extensions |
| 246 | } |
| 247 | |
| 248 | #[cfg(test)] |
| 249 | mod tests { |
no test coverage detected