tottenjordan/me-skittles/harness-writing
Claude Code and agent skill by tottenjordan/me-skittles
- community
Checking that the SKILL.md file is still in the repository.
Techniques for writing effective fuzzing harnesses across languages. Use when creating new fuzz targets or improving existing harness code.
Install
npx vskill@latest install tottenjordan/me-skittles/harness-writingSKILL.md
The same SKILL.md was published earlier as tottenjordan/me-skittles/harness-writing.
Writing Fuzzing Harnesses
A fuzzing harness is the entrypoint function that receives random data from the fuzzer and routes it to your system under test (SUT). The quality of your harness directly determines which code paths get exercised and whether critical bugs are found. A poorly written harness can miss entire subsystems or produce non-reproducible crashes.
Overview
The harness is the bridge between the fuzzer's random byte generation and your application's API. It must parse raw bytes into meaningful inputs, call target functions, and handle edge cases gracefully. The most important part of any fuzzing setup is the harness—if written poorly, critical parts of your application may not be covered.
Key Concepts
| Concept | Description | |
|---|---|---|
| Harness | Function that receives fuzzer input and calls target code under test | |
| SUT | System Under Test—the code being fuzzed | |
| Entry point | Function signature required by the fuzzer (e.g., LLVMFuzzerTestOneInput) | |
| FuzzedDataProvider | Helper class for structured extraction of typed data from raw bytes | |
| Determinism | Property that ensures same input always produces same behavior | |
| Interleaved fuzzing | Single harness that exercises multiple operations based on input |
When to Apply
Apply this technique when:
- Creating a new fuzz target for the first time
- Fuzz campaign has low code coverage or isn't finding bugs
- Crashes found during fuzzing are not reproducible
- Target API requires complex or structured inputs
- Multiple related functions should be tested together
Skip this technique when:
- Using existing well-tested harnesses from your project
- Tool provides automatic harness generation that meets your needs
- Target already has comprehensive fuzzing infrastructure
Quick Reference
| Task | Pattern | |||
|---|---|---|---|---|
| Minimal C++ harness | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | |||
| Minimal Rust harness | `fuzz_target!( | data: &[u8] | { ... })` | |
| Size validation | if (size < MIN_SIZE) return 0; | |||
| Cast to integers | uint32_t val = *(uint32_t*)(data); | |||
| Use FuzzedDataProvider | FuzzedDataProvider fuzzed_data(data, size); | |||
| Extract typed data (C++) | auto val = fuzzed_data.ConsumeIntegral<uint32_t>(); | |||
| Extract string (C++) | auto str = fuzzed_data.ConsumeBytesWithTerminator<char>(32, 0xFF); |
Tool-Specific Guidance
libFuzzer
Harness signature:
Compilation:
Integration tips:
- Use
FuzzedDataProvider.hfor structured input extraction - Compile with
-fsanitize=fuzzerto link the fuzzing runtime - Add sanitizers (
-fsanitize=address,undefined) to detect more bugs - Use
-gfor better stack traces when crashes occur - libFuzzer can start with empty corpus—no seed inputs required
Running:
Resources:
AFL++
AFL++ supports multiple harness styles. For best performance, use persistent mode:
Persistent mode harness:
Compilation:
Integration tips:
- Use persistent mode (
__AFL_LOOP) for 10-100x speedup - Consider deferred initialization (
__AFL_INIT()) to skip setup overhead - AFL++ requires at least one seed input in the corpus directory
- Use
AFL_USE_ASAN=1orAFL_USE_UBSAN=1for sanitizer builds
Running:
cargo-fuzz (Rust)
Harness signature:
With structured input (arbitrary crate):
Creating harness:
Integration tips:
- Use
arbitrarycrate for automatic struct deserialization - cargo-fuzz wraps libFuzzer, so all libFuzzer features work
- Compile with sanitizers automatically via cargo-fuzz
- Harnesses go in
fuzz/fuzz_targets/directory
Running:
Resources:
go-fuzz
Harness signature:
Building:
Integration tips:
- Return 1 for inputs that add coverage (optional—fuzzer can detect automatically)
- Return -1 for invalid inputs to deprioritize similar mutations
- go-fuzz handles persistence automatically
Running:
Troubleshooting
| Issue | Cause | Solution | |
|---|---|---|---|
| Low executions/sec | Harness is too slow (logging, I/O, complexity) | Profile harness, remove bottlenecks, mock I/O | |
| No crashes found | Coverage not reaching buggy code | Check coverage, improve harness to reach more paths | |
| Non-reproducible crashes | Non-determinism or global state | Remove randomness, reset globals between iterations | |
| Fuzzer exits immediately | Harness calls exit() | Replace exit() with abort() or return error | |
| Out of memory errors | Memory leaks in harness or SUT | Free allocations, use leak sanitizer to find leaks | |
| Crashes on empty input | Harness doesn't validate size | Add if (size < MIN_SIZE) return 0; | |
| Corpus not growing | Inputs too constrained or format too strict | Use FuzzedDataProvider or structure-aware fuzzing |
Reference material
[references/patterns.md](references/patterns.md) — the step-by-step process and common harness patterns
[references/advanced.md](references/advanced.md) — advanced usage, practical rules, and anti-patterns
Related Skills
Tools That Use This Technique
| Skill | How It Applies | |
|---|---|---|
| libfuzzer | Uses LLVMFuzzerTestOneInput harness signature with FuzzedDataProvider | |
| aflpp | Supports persistent mode harnesses with __AFL_LOOP for performance | |
| cargo-fuzz | Uses Rust-specific fuzz_target! macro with arbitrary crate integration | |
| atheris | Python harness takes bytes, calls Python functions | |
| ossfuzz | Requires harnesses in specific directory structure for cloud fuzzing |
Related Techniques
| Skill | Relationship | |
|---|---|---|
| coverage-analysis | Measure harness effectiveness—are you reaching target code? | |
| address-sanitizer | Detects bugs found by harness (buffer overflows, use-after-free) | |
| fuzzing-dictionary | Provide tokens to help fuzzer pass format checks in harness | |
| fuzzing-obstacles | Patch SUT when it violates harness rules (exit, non-determinism) |
Resources
Key External Resources
[Split Inputs in libFuzzer - Google Fuzzing Docs](https://github.com/google/fuzzing/blob/master/docs/split-inputs.md) Explains techniques for handling multiple input parameters in a single fuzzing harness, including use of magic separators and FuzzedDataProvider.
[Structure-Aware Fuzzing with Protocol Buffers](https://github.com/google/fuzzing/blob/master/docs/structure-aware-fuzzing.md) Advanced technique using protobuf as intermediate format with custom mutators to ensure fuzzer mutates message contents rather than format encoding.
[libFuzzer Documentation](https://llvm.org/docs/LibFuzzer.html) Official LLVM documentation covering harness requirements, best practices, and advanced features.
[cargo-fuzz Book](https://rust-fuzz.github.io/book/cargo-fuzz.html) Comprehensive guide to writing Rust fuzzing harnesses with cargo-fuzz and the arbitrary crate.
Video Resources
- Effective File Format Fuzzing - Conference talk on writing harnesses for file format parsers
- Modern Fuzzing of C/C++ Projects - Tutorial covering harness design patterns
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingclaude/testing-handbook-skills/skills/harness-writing/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/tottenjordan/me-skittles/harness-writing)