MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / evolve_corpus

Method evolve_corpus

src/execution/sanitize.rs:243–280  ·  view source on GitHub ↗

Evolving the fuzzing corpus by finding the new coverage corpus files and merge them in shared corpus.

(&self, program_path: &Path)

Source from the content-addressed store, hash-verified

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.

Callers 2

test_corpus_evoluationFunction · 0.80

Calls 7

get_file_dirnameFunction · 0.85
insert_featureMethod · 0.80
logMethod · 0.80
compileMethod · 0.45
pushMethod · 0.45

Tested by 1

test_corpus_evoluationFunction · 0.64