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

Method insert_switch_bytes_to_corpus

src/program/libfuzzer.rs:292–332  ·  view source on GitHub ↗
(
        &self,
        seed_corpus: &Path,
        switch_id: u16,
        in_corpus_dir: &Path,
        out_corpus_dir: &Path,
    )

Source from the content-addressed store, hash-verified

290 }
291
292 fn insert_switch_bytes_to_corpus(
293 &self,
294 seed_corpus: &Path,
295 switch_id: u16,
296 in_corpus_dir: &Path,
297 out_corpus_dir: &Path,
298 ) -> Result<()> {
299 if !std::fs::exists(in_corpus_dir)? {
300 log::warn!("Corpus directory doesn't exist: {in_corpus_dir:?}, skip it and continue...");
301 return Ok(())
302 }
303
304 let files = crate::deopt::utils::read_all_files_in_dir(in_corpus_dir)?;
305 for file in &files {
306 let lib_corpus = std::fs::read(file)?;
307 let content = if self.use_constraint {
308 let literal_corpus = std::fs::read(seed_corpus)?;
309 [
310 switch_id.to_bytes(),
311 lib_corpus,
312 FuzzerShim::get_magic_bytes(),
313 literal_corpus,
314 ]
315 .concat()
316 } else {
317 [switch_id.to_bytes(), lib_corpus].concat()
318 };
319 let to_file: PathBuf = [
320 PathBuf::from(out_corpus_dir),
321 format!(
322 "{}_{switch_id}",
323 file.file_name().unwrap().to_string_lossy()
324 )
325 .into(),
326 ]
327 .iter()
328 .collect();
329 std::fs::write(to_file, content)?;
330 }
331 Ok(())
332 }
333
334 fn synthesis_batch(&mut self, batch_id: &Vec<usize>) -> Result<String> {
335 let mut stmts = String::new();

Callers 1

fuse_corpusMethod · 0.80

Calls 1

read_all_files_in_dirFunction · 0.85

Tested by

no test coverage detected