Loading...
Loading...
Compare original and translation side by side
| Concept | Description |
|---|---|
| helper.py | CLI script for building images, building fuzzers, and running harnesses locally |
| Base Images | Hierarchical Docker images providing build dependencies and compilers |
| project.yaml | Configuration file defining project metadata for OSS-Fuzz enrollment |
| Dockerfile | Project-specific image with build dependencies |
| build.sh | Script that builds fuzzing harnesses for your project |
| Criticality Score | Metric used by OSS-Fuzz team to evaluate project acceptance |
| 概念 | 描述 |
|---|---|
| helper.py | 用于构建镜像、构建模糊测试器以及在本地运行测试harness的CLI脚本 |
| Base Images | 分层Docker镜像,提供构建依赖和编译器 |
| project.yaml | 定义OSS-Fuzz注册项目元数据的配置文件 |
| Dockerfile | 包含项目构建依赖的项目专属镜像 |
| build.sh | 为你的项目构建模糊测试harness的脚本 |
| Criticality Score | OSS-Fuzz团队用于评估项目是否可被接纳的指标 |
| Task | Command |
|---|---|
| Clone OSS-Fuzz | |
| Build project image | |
| Build fuzzers with ASan | |
| Run specific harness | |
| Generate coverage report | |
| Check helper.py options | |
| 任务 | 命令 |
|---|---|
| 克隆OSS-Fuzz | |
| 构建项目镜像 | |
| 使用ASan构建模糊测试器 | |
| 运行指定的harness | |
| 生成覆盖率报告 | |
| 查看helper.py选项 | |
git clone https://github.com/google/oss-fuzz
cd oss-fuzz
python3 infra/helper.py --helpgit clone https://github.com/google/oss-fuzz
cd oss-fuzz
python3 infra/helper.py --helppython3 infra/helper.py build_image --pull <project-name>python3 infra/helper.py build_image --pull <project-name>python3 infra/helper.py build_fuzzers --sanitizer=address <project-name>--sanitizer=address/build/out/<project-name>/python3 infra/helper.py build_fuzzers --sanitizer=address <project-name>--sanitizer=address/build/out/<project-name>/python3 infra/helper.py run_fuzzer <project-name> <harness-name> [<fuzzer-args>]python3 infra/helper.py run_fuzzer <project-name> <harness-name> [<fuzzer-args>]python3 infra/helper.py build_fuzzers --sanitizer=coverage <project-name>
python3 infra/helper.py coverage <project-name>--no-corpus-downloadpython3 infra/helper.py build_fuzzers --sanitizer=coverage <project-name>
python3 infra/helper.py coverage <project-name>--no-corpus-downloadundefinedundefined
**Expected Output:**undefined
**预期输出:**undefinedprojects/<your-project>/homepage: "https://github.com/yourorg/yourproject"
language: c++
primary_contact: "your-email@example.com"
main_repo: "https://github.com/yourorg/yourproject"
fuzzing_engines:
- libfuzzer
sanitizers:
- address
- undefinedFROM gcr.io/oss-fuzz-base/base-builder
RUN apt-get update && apt-get install -y \
autoconf \
automake \
libtool \
pkg-config
RUN git clone --depth 1 https://github.com/yourorg/yourproject
WORKDIR yourproject
COPY build.sh $SRC/#!/bin/bash -eu
./autogen.sh
./configure --disable-shared
make -j$(nproc)projects/<your-project>/homepage: "https://github.com/yourorg/yourproject"
language: c++
primary_contact: "your-email@example.com"
main_repo: "https://github.com/yourorg/yourproject"
fuzzing_engines:
- libfuzzer
sanitizers:
- address
- undefinedFROM gcr.io/oss-fuzz-base/base-builder
RUN apt-get update && apt-get install -y \
autoconf \
automake \
libtool \
pkg-config
RUN git clone --depth 1 https://github.com/yourorg/yourproject
WORKDIR yourproject
COPY build.sh $SRC/#!/bin/bash -eu
./autogen.sh
./configure --disable-shared
make -j$(nproc)undefinedundefinedbase_imagebase_clangbase_builder_gobase_builderbase_imagebase_clangbase_builder_gobase_builderbase_clangbase_runnerbase_clangbase_runner| Tip | Why It Helps |
|---|---|
| Don't manually copy source code | Project Dockerfile likely already pulls latest version |
| Check existing projects | Browse oss-fuzz/projects for examples |
| Keep harnesses in separate repo | Like curl-fuzzer - cleaner organization |
| Use specific compiler versions | Base images provide consistent build environment |
| Install dependencies in Dockerfile | May require approval for OSS-Fuzz enrollment |
| 技巧 | 优势 |
|---|---|
| 不要手动复制源代码 | 项目Dockerfile可能已经拉取了最新版本 |
| 查看现有项目 | 浏览oss-fuzz/projects获取示例 |
| 将harness放在单独的仓库中 | 类似于curl-fuzzer - 组织更清晰 |
| 使用特定版本的编译器 | 基础镜像提供一致的构建环境 |
| 在Dockerfile中安装依赖 | OSS-Fuzz注册可能需要审批 |
| Anti-Pattern | Problem | Correct Approach |
|---|---|---|
| Manually pulling source in build.sh | Doesn't use latest version | Let Dockerfile handle git clone |
| Copying code to OSS-Fuzz repo | Hard to maintain, violates separation | Reference external harness repo |
| Ignoring base image versions | Build inconsistencies | Use provided base images and compilers |
| Skipping local testing | Wastes CI resources | Use helper.py locally before PR |
| Not checking build status | Unnoticed build failures | Monitor build status page regularly |
| 反模式 | 问题 | 正确做法 |
|---|---|---|
| 在build.sh中手动拉取源代码 | 无法使用最新版本 | 让Dockerfile处理git克隆 |
| 将代码复制到OSS-Fuzz仓库 | 难以维护,违反分离原则 | 引用外部harness仓库 |
| 忽略基础镜像版本 | 构建不一致 | 使用提供的基础镜像和编译器 |
| 跳过本地测试 | 浪费CI资源 | 在提交PR前使用helper.py进行本地测试 |
| 不检查构建状态 | 未发现构建失败 | 定期监控构建状态页面 |
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
// Your fuzzing logic
return 0;
}$CXX $CXXFLAGS -std=c++11 -I. \
harness.cc -o $OUT/harness \
$LIB_FUZZING_ENGINE ./libproject.a$LIB_FUZZING_ENGINE-fsanitize=fuzzerextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
// 你的模糊测试逻辑
return 0;
}$CXX $CXXFLAGS -std=c++11 -I. \
harness.cc -o $OUT/harness \
$LIB_FUZZING_ENGINE ./libproject.a$LIB_FUZZING_ENGINE-fsanitize=fuzzerfuzzing_engines:
- afl
- libfuzzerfuzzing_engines:
- afl
- libfuzzerimport atheris
import sys
import cbor2
@atheris.instrument_func
def TestOneInput(data):
fdp = atheris.FuzzedDataProvider(data)
try:
cbor2.loads(data)
except (cbor2.CBORDecodeError, ValueError):
pass
def main():
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()
if __name__ == "__main__":
main()pip3 install .
for fuzzer in $(find $SRC -name 'fuzz_*.py'); do
compile_python_fuzzer $fuzzer
donecompile_python_fuzzerimport atheris
import sys
import cbor2
@atheris.instrument_func
def TestOneInput(data):
fdp = atheris.FuzzedDataProvider(data)
try:
cbor2.loads(data)
except (cbor2.CBORDecodeError, ValueError):
pass
def main():
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()
if __name__ == "__main__":
main()pip3 install .
for fuzzer in $(find $SRC -name 'fuzz_*.py'); do
compile_python_fuzzer $fuzzer
donecompile_python_fuzzerlanguage: rust
fuzzing_engines:
- libfuzzer
sanitizers:
- address # Only AddressSanitizer supported for Rustcargo fuzz build -O --debug-assertions
cp fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_target_1 $OUT/language: rust
fuzzing_engines:
- libfuzzer
sanitizers:
- address # Rust仅支持AddressSanitizercargo fuzz build -O --debug-assertions
cp fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_target_1 $OUT/| Issue | Cause | Solution |
|---|---|---|
| Build fails with missing dependencies | Dependencies not in Dockerfile | Add |
| Harness crashes immediately | Missing input validation | Add size checks in harness |
| Coverage is 0% | Harness not reaching target code | Verify harness actually calls target functions |
| Build timeout | Complex build process | Optimize build.sh, consider parallel builds |
| Sanitizer errors in build | Incompatible flags | Use flags provided by OSS-Fuzz environment variables |
| Cannot find source code | Wrong working directory in Dockerfile | Set WORKDIR or use absolute paths |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 构建失败,提示缺少依赖 | Dockerfile中未包含依赖 | 在Dockerfile中添加 |
| Harness立即崩溃 | 缺少输入验证 | 在harness中添加大小检查 |
| 覆盖率为0% | Harness未触达目标代码 | 验证harness是否实际调用了目标函数 |
| 构建超时 | 构建过程复杂 | 优化build.sh,考虑并行构建 |
| 构建中出现Sanitizer错误 | 标志不兼容 | 使用OSS-Fuzz环境变量提供的标志 |
| 无法找到源代码 | Dockerfile中的工作目录错误 | 设置WORKDIR或使用绝对路径 |
| Skill | How It Applies |
|---|---|
| libfuzzer | Primary fuzzing engine used by OSS-Fuzz |
| aflpp | Alternative fuzzing engine supported by OSS-Fuzz |
| atheris | Used for fuzzing Python projects in OSS-Fuzz |
| cargo-fuzz | Used for Rust projects in OSS-Fuzz |
| 技能 | 应用方式 |
|---|---|
| libfuzzer | OSS-Fuzz使用的主要模糊测试引擎 |
| aflpp | OSS-Fuzz支持的替代模糊测试引擎 |
| atheris | 用于在OSS-Fuzz中模糊测试Python项目 |
| cargo-fuzz | 用于在OSS-Fuzz中模糊测试Rust项目 |
| Skill | Relationship |
|---|---|
| coverage-analysis | OSS-Fuzz generates coverage reports via helper.py |
| address-sanitizer | Default sanitizer for OSS-Fuzz projects |
| fuzz-harness-writing | Essential for enrolling projects in OSS-Fuzz |
| corpus-management | OSS-Fuzz maintains corpus for enrolled projects |
| 技能 | 关系 |
|---|---|
| coverage-analysis | OSS-Fuzz通过helper.py生成覆盖率报告 |
| address-sanitizer | OSS-Fuzz项目的默认Sanitizer |
| fuzz-harness-writing | 项目加入OSS-Fuzz的必备技能 |
| corpus-management | OSS-Fuzz为已注册项目维护语料库 |