본문으로 건너뛰기
Skillpedia
테스트8.0k · #12716

coverage-analysis

하는 일

퍼징 실행이 프로그램의 얼마나 많은 부분을 실행하는지 측정하고 결과를 설명합니다. 퍼즈 테스트가 실제로 효과가 있는지 알고 싶은 개발자를 위한 것입니다.

사용하는 경우

  • ✓퍼징이 새 코드를 찾지 못하고 멈춰서 그 이유를 알고 싶을 때.
  • ✓퍼즈 테스트를 바꾼 뒤 커버리지가 좋아졌는지 확인하고 싶을 때.
  • ✓어떤 코드 영역이 테스트에서 한 번도 도달하지 않는지 이해해야 하는 경우.

스킬 링크

https://github.com/trailofbits/skills/blob/main/plugins/testing-handbook-skills/skills/coverage-analysis/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/trailofbits/skills/blob/main/plugins/testing-handbook-skills/skills/coverage-analysis/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제 퍼징 실행이 실제로 도달하는 코드와 놓치는 코드를 보여 주실 수 있나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 커버리지 추적과 함께 프로그램을 빌드하고, 저장된 테스트 입력을 실행한 다음 커버리지 보고서를 읽습니다. 그다음 테스트되지 않은 영역을 가리키고, 테스트 입력이나 시드 파일을 바꾸는 방법을 제안합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Coverage Analysis

Coverage analysis is essential for understanding which parts of your code are exercised during fuzzing. It helps identify fuzzing blockers like magic value checks and tracks the effectiveness of harness improvements over time.

Overview

Code coverage during fuzzing serves two critical purposes:

  1. Assessing harness effectiveness: Understand which parts of your application are actually executed by your fuzzing harnesses
  2. Tracking fuzzing progress: Monitor how coverage changes when updating harnesses, fuzzers, or the system under test (SUT)

Coverage is a proxy for fuzzer capability and performance. While coverage is not ideal for measuring fuzzer performance in absolute terms, it reliably indicates whether your harness works effectively in a given setup.

Key Concepts

Concept Description
Coverage instrumentation Compiler flags that track which code paths are executed
Corpus coverage Coverage achieved by running all test cases in a fuzzing corpus
Magic value checks Hard-to-discover conditional checks that block fuzzer progress
Coverage-guided fuzzing Fuzzing strategy that prioritizes inputs that discover new code paths
Coverage report Visual or textual representation of executed vs. unexecuted code

When to Apply

Apply this technique when:

  • Starting a new fuzzing campaign to establish a baseline
  • Fuzzer appears to plateau without finding new paths
  • After harness modifications to verify improvements
  • When migrating between different fuzzers
  • Identifying areas requiring dictionary entries or seed inputs
  • Debugging why certain code paths aren't reached

Skip this technique when:

  • Fuzzing campaign is actively finding crashes
  • Coverage infrastructure isn't set up yet
  • Working with extremely large codebases where full coverage reports are impractical
  • Fuzzer's internal coverage metrics are sufficient for your needs

Quick Reference

Task Command/Pattern
LLVM coverage instrumentation (C/C++) -fprofile-instr-generate -fcoverage-mapping
GCC coverage instrumentation -ftest-coverage -fprofile-arcs
cargo-fuzz coverage (Rust) cargo +nightly fuzz coverage <target>
Generate LLVM profile data llvm-profdata merge -sparse file.profraw -o file.profdata
LLVM coverage report llvm-cov report ./binary -instr-profile=file.profdata
LLVM HTML report llvm-cov show ./binary -instr-profile=file.profdata -format=html -output-dir html/
gcovr HTML report gcovr --html-details -o coverage.html

Ideal Coverage Workflow

The following workflow represents best practices for integrating coverage analysis into your fuzzing campaigns:

[Fuzzing Campaign]
       |
       v
[Generate Corpus]
       |
       v
[Coverage Analysis]
       |
       +---> Coverage Increased? --> Continue fuzzing with larger corpus
       |
       +---> Coverage Decreased? --> Fix harness or investigate SUT changes
       |
       +---> Coverage Plateaued? --> Add dictionary entries or seed inputs

Key principle: Use the corpus generated after each fuzzing campaign to calculate coverage, rather than real-time fuzzer statistics. This approach provides reproducible, comparable measurements across different fuzzing tools.

Step-by-Step

Step 1: Build with Coverage Instrumentation

Choose your instrumentation method based on toolchain:

LLVM/Clang (C/C++):

clang++ -fprofile-instr-generate -fcoverage-mapping \
  -O2 -DNO_MAIN \
  main.cc harness.cc execute-rt.cc -o fuzz_exec

GCC (C/C++):

g++ -ftest-coverage -fprofile-arcs \
  -O2 -DNO_MAIN \
  main.cc harness.cc execute-rt.cc -o fuzz_exec_gcov

Rust:

rustup toolchain install nightly --component llvm-tools-preview
cargo +nightly fuzz coverage fuzz_target_1

Step 2: Create Execution Runtime (C/C++ only)

For C/C++ projects, create a runtime that executes your corpus:

// execute-rt.cc
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <stdint.h>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);

void load_file_and_test(const char *filename) {
    FILE *file = fopen(filename, "rb");
    if (file == NULL) {
        printf("Failed to open file: %s\n", filename);
        return;
    }

    fseek(file, 0, SEEK_END);
    long filesize = ftell(file);
    r
자주 묻는 질문

커버리지에는 어떤 도구를 쓰나요?

llvm-cov, lcov, 또는 퍼저 자체의 커버리지 출력을 씁니다.

커버리지가 높으면 항상 좋은가요?

항상 그렇지는 않습니다. 커버리지는 도움이 되는 대리 지표이지, 퍼저의 좋음을 정확히 재는 척도가 아니라고 설명합니다.

퍼저가 더 깊이 가지 못하게 막는 것은 무엇인가요?

정확한 값에 대한 까다로운 검사이며, 보고서에서 커버되지 않은 부분을 읽어서 찾을 수 있습니다.

상세 정보

작성자의 원본 설명

Measures and interprets what a fuzzing campaign actually reaches, using llvm-cov, lcov, or a fuzzer's own coverage output. Covers baselining a new campaign, reading coverage reports, and turning uncovered regions into harness, seed, or dictionary work. Use when a fuzzer plateaus, when judging whether a harness is effective, after changing a harness, or when asking why some code is never reached.

repo: trailofbits/skills

인기도

GitHub 스타
8.0k
순위
#12716
라이선스
CC-BY-SA-4.0
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬