Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
7e6c1a2
Remove build log write files
joyguoguo Jul 22, 2025
a7e447e
Remove build log write files
joyguoguo Jul 22, 2025
fb4da2a
use logging mdule
joyguoguo Jul 22, 2025
e582af6
use precise logging
joyguoguo Jul 22, 2025
02f9269
use logging
joyguoguo Jul 22, 2025
15a7095
use precise exception log info
joyguoguo Jul 22, 2025
9a471aa
correct type problems
joyguoguo Jul 22, 2025
026614b
correct some mistakes
joyguoguo Jul 22, 2025
74f44dc
correct some mistakes
joyguoguo Jul 22, 2025
413c2dd
correct
joyguoguo Jul 22, 2025
c8b755d
modify discover fuzz target
joyguoguo Jul 22, 2025
4b92185
modify the oss-fuzz dir
joyguoguo Jul 22, 2025
a8e58e8
Redirect the output to an empty device without retaining any output
joyguoguo Jul 22, 2025
ae7e7c1
add always yes
joyguoguo Jul 22, 2025
2dc8f97
split the build script
joyguoguo Jul 23, 2025
ebb68c9
split the build script
joyguoguo Jul 23, 2025
5b12877
build scripts test successfully
joyguoguo Jul 23, 2025
40588d4
build.py
joyguoguo Jul 23, 2025
5b52393
collect targets first and then run
joyguoguo Jul 23, 2025
8285e3f
list, tuple, ptional
joyguoguo Jul 23, 2025
7e9add9
list,tuple,optional
joyguoguo Jul 23, 2025
6afc919
translate
joyguoguo Jul 24, 2025
ea76d9d
build_fuzz.py, run_fuzz_all_target.py
joyguoguo Jul 24, 2025
b0f7b86
correct
joyguoguo Jul 24, 2025
19fa83e
original
joyguoguo Jul 24, 2025
47cf6e9
record input
joyguoguo Jul 24, 2025
76c63ac
Fatal error in main program: cannot unpack non-iterable NoneType object
joyguoguo Jul 24, 2025
1c608dc
name 'target_functions' is not defined
joyguoguo Jul 24, 2025
34ef833
准备大改
joyguoguo Jul 24, 2025
510cbe7
create modify file script add"print(data)" to each fuzz_.py
joyguoguo Jul 25, 2025
61009ab
build_fuzzer script
joyguoguo Jul 25, 2025
d3bbc13
modify tuple dict list
joyguoguo Jul 25, 2025
62847f3
remove stdout stderr in build fuzz
joyguoguo Jul 25, 2025
4a5f9ff
test successfully
joyguoguo Jul 25, 2025
3f736cb
rename run fuzz ds to run fuzz print1
joyguoguo Jul 25, 2025
d5c2b27
add print(data ) to fuzz target and rename the file with "_print1"
joyguoguo Jul 25, 2025
d74a6bf
oss -fuzz change
joyguoguo Jul 25, 2025
c6a6c23
rename the print1.py
joyguoguo Jul 25, 2025
9d5c9b6
modify the exegesis
joyguoguo Jul 25, 2025
521045e
modify
joyguoguo Jul 25, 2025
6c18832
modify log name
joyguoguo Jul 25, 2025
679ec48
type error
joyguoguo Jul 26, 2025
b4d1811
list dict tuple
joyguoguo Jul 26, 2025
d030841
type error
joyguoguo Jul 26, 2025
3f9df9d
construct errors module
joyguoguo Jul 28, 2025
85b7904
run_command module
joyguoguo Jul 28, 2025
40102b4
combine the run_command instrument to one file
joyguoguo Jul 28, 2025
e0c7740
remove the run_command
joyguoguo Jul 29, 2025
0631504
modify
joyguoguo Jul 29, 2025
5e28b5c
mytype check
joyguoguo Jul 29, 2025
368c0e4
mytype
joyguoguo Jul 29, 2025
1be1dfa
mytype
joyguoguo Jul 29, 2025
09ba145
mytype
joyguoguo Jul 29, 2025
7a1f248
translate
joyguoguo Jul 29, 2025
6a062bb
remove run command
joyguoguo Jul 29, 2025
26eceeb
timeout - shell instrument
joyguoguo Jul 29, 2025
7e91c6c
correct in out error and return Popen directly
joyguoguo Jul 29, 2025
f9edfaf
ready to change from rust script
joyguoguo Aug 2, 2025
3821133
修改build_image
joyguoguo Aug 4, 2025
6e5c764
y/n
joyguoguo Aug 4, 2025
0029059
correct repo_id and repo_name in main
joyguoguo Aug 4, 2025
1d815eb
test build_image 构建日志
joyguoguo Aug 4, 2025
4333456
add build_fuzzer
joyguoguo Aug 4, 2025
3a0565f
fuzz and testgen
joyguoguo Aug 4, 2025
779fb40
correct run_one_target
joyguoguo Aug 5, 2025
0afec3b
fuzz ok
joyguoguo Aug 5, 2025
ba61ca1
transform
joyguoguo Aug 5, 2025
58d1f76
testgen need to ^ help: add `;` here
joyguoguo Aug 5, 2025
9236822
test successful
joyguoguo Aug 5, 2025
310b079
example output project
joyguoguo Aug 5, 2025
5ceb873
type error
joyguoguo Aug 5, 2025
d31a333
English ver
joyguoguo Aug 5, 2025
6717dad
delete privious scripts
joyguoguo Aug 5, 2025
1266606
python template
joyguoguo Aug 6, 2025
d42927f
python template
joyguoguo Aug 6, 2025
f8941f1
correct the template
joyguoguo Aug 6, 2025
b357a52
ver2 wrong template
joyguoguo Aug 7, 2025
1637e23
ok
joyguoguo Aug 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 57 additions & 55 deletions fuzz/build_oss_fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,99 +12,91 @@
--sanitizer address \
--workers 8
"""

import os
import sys
import subprocess
import argparse
from datetime import datetime
from pathlib import Path
from typing import List, Optional, Tuple
from multiprocessing import Pool, cpu_count
import logging

# --- Global configuration ---
HOME_DIR = Path.home()
OSS_FUZZ_DIR = HOME_DIR / "FuzzAug" / "fuzz" / "oss-fuzz"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path is wrong; we cannot assume FuzzAug is placed in the user's home directory.
Please use a CLI argument to the main function pointing to "oss-fuzz" as a relative path from where the user runs the script.

That being said, I also recommend placing the oss-fuzz submodule at the root of this project, on the same level as the other modules.

LOG_DIR = OSS_FUZZ_DIR / "build_logs"

def setup_logging(project_name: str) -> Path:
"""Create a timestamped log file for a single project"""
LOG_DIR.mkdir(parents=True, exist_ok=True)
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
return LOG_DIR / f"build_{project_name}_{timestamp}.log"

def log_and_print(message: str, log_file: Path, to_stdout: bool = True):
"""Write message to log and print to console"""
if to_stdout:
print(f"[PID:{os.getpid()}] {message}")
with open(log_file, "a", encoding="utf-8") as f:
f.write(f"{datetime.now().isoformat()} {message}\n")

def run_command(
cmd: str,
log_msg: str,
log_file: Path,
cmd: str,
log_msg: str,
allowed_exit_codes: Optional[List[int]] = None
) -> bool:
"""Execute a shell command and stream output to log in real-time"""
"""Execute a shell command and stream output to console"""
allowed_exit_codes = allowed_exit_codes or []
log_and_print(f"▶️ {log_msg}...", log_file, to_stdout=False)
log_and_print(f" $ {cmd}", log_file, to_stdout=False)

logging.info(f"▶️ {log_msg}")
logging.debug(f"$ {cmd}")

try:
process = subprocess.Popen(
f"yes | {cmd}", # Auto-confirm all prompts
f"yes | {cmd}",
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
errors="replace"
)
with open(log_file, "a", encoding="utf-8") as f:
if process.stdout is not None:
for line in iter(process.stdout.readline, ""):
f.write(line)
else:
log_and_print("⚠️ Warning: process.stdout is None", log_file)
except FileNotFoundError:
logging.error(f"Command not found: {cmd}")
return False
except OSError as e:
logging.error(f"OS error while executing command: {e}")
return False
except ValueError as e:
logging.error(f"Invalid arguments to Popen: {e}")
return False

try:
if process.stdout:
for line in iter(process.stdout.readline, ""):
sys.stdout.write(line)
sys.stdout.flush()
process.wait()
exit_code = process.returncode
if exit_code in [0, *allowed_exit_codes]:
log_and_print(f"✅ Command completed successfully", log_file, to_stdout=False)
logging.info("✅ Command completed successfully")
return True
log_and_print(f"❌ Command failed (exit code: {exit_code})", log_file)
logging.error(f"❌ Command failed (exit code: {exit_code})")
return False
except KeyboardInterrupt:
logging.warning("⛔️ Command interrupted by user")
process.terminate()
return False
except Exception as e:
log_and_print(f"💥 Execution exception: {e}", log_file)
logging.exception(f"Unexpected error during process execution: {e}")
return False


def build_project(project_name: str, sanitizer: str) -> Tuple[bool, str]:
"""Build workflow for a single project"""
log_file = setup_logging(project_name)
os.chdir(OSS_FUZZ_DIR)

log_and_print("="*60, log_file)
log_and_print(f"🔨 Starting build for project: {project_name}", log_file)
log_and_print(f"📝 Log path: {log_file}", log_file)
log_and_print("="*60, log_file)

# 1. Build Docker image
logging.info("=" * 60)
logging.info(f"🔨 Starting build for project: {project_name}")
logging.info("=" * 60)

if not run_command(
f"python3 infra/helper.py build_image {project_name}",
"Step 1/2: Building Docker image",
log_file
"Step 1/2: Building Docker image"
):
return (False, project_name)

# 2. Compile Fuzzers
if not run_command(
f"python3 infra/helper.py build_fuzzers --sanitizer {sanitizer} {project_name}",
f"Step 2/2: Compiling Fuzzers (sanitizer={sanitizer})",
log_file
f"Step 2/2: Compiling Fuzzers (sanitizer={sanitizer})"
):
return (False, project_name)

log_and_print(f"✅ Project {project_name} build completed", log_file)
logging.info(f"✅ Project {project_name} build completed")
return (True, project_name)

def main():
Expand All @@ -114,23 +106,33 @@ def main():
parser.add_argument("--workers", type=int, default=cpu_count())
args = parser.parse_args()

# Read project list
logging.basicConfig(
level=logging.INFO,
format='[%(levelname)s] [PID:%(process)d] %(message)s'
)

if not os.path.isfile(args.project_list):
logging.error(f"Project list file not found: {args.project_list}")
sys.exit(1)

try:
with open(args.project_list, "r") as f:
with open(args.project_list, "r", encoding="utf-8") as f:
projects = [line.strip() for line in f if line.strip()]
except Exception as e:
print(f"❌ Failed to read project list: {e}")
except OSError as e:
logging.error(f"OS error while reading project list: {e}")
sys.exit(1)
except UnicodeDecodeError as e:
logging.error(f"Encoding error while reading file: {e}")
sys.exit(1)

# Parallel build
with Pool(args.workers) as pool:
results = pool.starmap(build_project, [(p, args.sanitizer) for p in projects])

# Output results
failed = [p for success, p in results if not success]
print(f"\n📊 Build completed: Success {len(projects)-len(failed)}/{len(projects)}")
logging.info(f"\n📊 Build completed: Success {len(projects) - len(failed)}/{len(projects)}")
if failed:
print("❌ Failed projects: " + ", ".join(failed))
logging.warning("❌ Failed projects: " + ", ".join(failed))

if __name__ == "__main__":
main()
main()

Loading