Evolving the fuzzing corpus by finding the new coverage corpus files and merge them in shared corpus.
(&self, program_path: &Path)
| 241 | |
| 242 | // Evolving the fuzzing corpus by finding the new coverage corpus files and merge them in shared corpus. |
| 243 | fn evolve_corpus(&self, program_path: &Path) -> Result<()> { |
| 244 | log::debug!("Evolve fuzzing corpus by merge new coverage corpora"); |
| 245 | let work_dir = crate::deopt::utils::get_file_dirname(program_path); |
| 246 | let time_logger = TimeUsage::new(work_dir.clone()); |
| 247 | let fuzzer_binary = program_path.with_extension("sancov"); |
| 248 | self.compile(vec![program_path], &fuzzer_binary, super::Compile::Minimize)?; |
| 249 | |
| 250 | let global_feature_file = self.deopt.get_library_global_feature_file()?; |
| 251 | let mut global_featuers: GlobalFeature = if global_feature_file.exists() { |
| 252 | let buf = std::fs::read(&global_feature_file)?; |
| 253 | serde_json::from_slice(&buf)? |
| 254 | } else { |
| 255 | GlobalFeature::init_by_corpus(self, &fuzzer_binary)? |
| 256 | }; |
| 257 | |
| 258 | let corpus: PathBuf = [work_dir.clone(), "corpus".into()].iter().collect(); |
| 259 | |
| 260 | let corpus_dict = Self::collect_sancov_from_corpus(&fuzzer_binary, &corpus)?; |
| 261 | let mut intrestings = Vec::new(); |
| 262 | for (corpus_file, sancov) in corpus_dict { |
| 263 | let mut has_new = false; |
| 264 | let features = sancov.covered_points; |
| 265 | for fe in features { |
| 266 | if global_featuers.insert_feature(fe) { |
| 267 | has_new = true; |
| 268 | } |
| 269 | } |
| 270 | if has_new { |
| 271 | intrestings.push(corpus_file); |
| 272 | } |
| 273 | } |
| 274 | log::debug!("Find {} new interesting corpus files to evolve the corpus.", intrestings.len()); |
| 275 | self.deopt.copy_file_to_shared_corpus(intrestings)?; |
| 276 | let buf = serde_json::to_vec(&global_featuers)?; |
| 277 | std::fs::write(global_feature_file, buf)?; |
| 278 | time_logger.log("update")?; |
| 279 | Ok(()) |
| 280 | } |
| 281 | |
| 282 | /// After the first half of converge, performs sanitization on the seeds again. It aims to: |
| 283 | /// Sanitize the erroneous programs that were ignored due to no suitable fuzzing corpus to trigger the error. |