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

Method concurrent_transform

src/execution/mod.rs:658–714  ·  view source on GitHub ↗

concurrently transform programs to fuzzers.

(
        &self,
        programs: &Vec<PathBuf>,
        core: usize,
        use_cons: bool,
        corpus: &Vec<PathBuf>,
    )

Source from the content-addressed store, hash-verified

656
657 /// concurrently transform programs to fuzzers.
658 pub fn concurrent_transform(
659 &self,
660 programs: &Vec<PathBuf>,
661 core: usize,
662 use_cons: bool,
663 corpus: &Vec<PathBuf>,
664 ) -> Result<()> {
665 let pool = ThreadPool::new(core);
666 let error_occurred = Arc::new(AtomicBool::new(false));
667
668 for (i, program) in programs.iter().enumerate() {
669 let error_occurred = Arc::clone(&error_occurred);
670 let program = program.clone();
671 let corpora = corpus[i].clone();
672
673 // the constraints are load in harness.
674 pool.execute(move || {
675 // If an error has occurred in another thread, stop this one
676 if error_occurred.load(Ordering::SeqCst) {
677 return;
678 }
679 let mut cmd = Command::new("cargo");
680 let cmd = cmd
681 .arg("run")
682 .arg("--bin")
683 .arg("harness")
684 .arg("--")
685 .arg(get_library_name())
686 .arg("transform")
687 .arg(&program);
688 if use_cons {
689 cmd.arg("-u");
690 cmd.arg("-p");
691 cmd.arg(&corpora);
692 }
693 let output = cmd
694 .stdin(Stdio::null())
695 .stdout(Stdio::null())
696 .stderr(Stdio::piped())
697 .output()
698 .expect("failed to execute the concurrent transform process");
699 if !output.status.success() {
700 error_occurred.store(true, Ordering::SeqCst);
701 log::error!(
702 "Transform {program:?} to fuzzer error!\n{}",
703 String::from_utf8_lossy(&output.stderr)
704 );
705 }
706 });
707 }
708 pool.join();
709 if error_occurred.load(Ordering::SeqCst) {
710 log::error!("Concurrent transform failed!");
711 //eyre::bail!("Concurrent transform failed!");
712 }
713 Ok(())
714 }
715

Callers 1

exploit_transformMethod · 0.80

Calls 3

get_library_nameFunction · 0.85
loadMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected