[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75F1WSVYMV7B4NEFPWH5R65":3,"skill-same:01M75F1WSVYMV7B4NEFPWH5R65":47},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":6,"updatedAt":32,"install":33,"resources":46},"01M75F1WSVYMV7B4NEFPWH5R65","libfuzzer",null,"Coverage-guided fuzzer built into LLVM for C\u002FC++ projects. Use for fuzzing C\u002FC++ code that can be compiled with Clang.","agisota\u002Fold-one","agisota","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F121413592?v=4","01M75B4BRNT67EC1NDRT8QZEP2","01M75B4BS7QR9VP580MSCPTS3X",3,"MIT","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Flibfuzzer\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: libfuzzer\ntype: fuzzer\ndescription: >\n  Coverage-guided fuzzer built into LLVM for C\u002FC++ projects. Use for fuzzing\n  C\u002FC++ code that can be compiled with Clang.\n---\n\n# libFuzzer\n\nlibFuzzer is an in-process, coverage-guided fuzzer that is part of the LLVM project. It's the recommended starting point for fuzzing C\u002FC++ projects due to its simplicity and integration with the LLVM toolchain. While libFuzzer has been in maintenance-only mode since late 2022, it is easier to install and use than its alternatives, has wide support, and will be maintained for the foreseeable future.\n\n## When to Use\n\n| Fuzzer | Best For | Complexity |\n|--------|----------|------------|\n| libFuzzer | Quick setup, single-project fuzzing | Low |\n| AFL++ | Multi-core fuzzing, diverse mutations | Medium |\n| LibAFL | Custom fuzzers, research projects | High |\n| Honggfuzz | Hardware-based coverage | Medium |\n\n**Choose libFuzzer when:**\n- You need a simple, quick setup for C\u002FC++ code\n- Project uses Clang for compilation\n- Single-core fuzzing is sufficient initially\n- Transitioning to AFL++ later is an option (harnesses are compatible)\n\n**Note:** Fuzzing harnesses written for libFuzzer are compatible with AFL++, making it easy to transition if you need more advanced features like better multi-core support.\n\n## Quick Start\n\n```c++\n#include \u003Cstdint.h>\n#include \u003Cstddef.h>\n\nextern \"C\" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {\n    \u002F\u002F Validate input if needed\n    if (size \u003C 1) return 0;\n\n    \u002F\u002F Call your target function with fuzzer-provided data\n    my_target_function(data, size);\n\n    return 0;\n}\n```\n\nCompile and run:\n```bash\nclang++ -fsanitize=fuzzer,address -g -O2 harness.cc target.cc -o fuzz\nmkdir corpus\u002F\n.\u002Ffuzz corpus\u002F\n```\n\n## Installation\n\n### Prerequisites\n\n- LLVM\u002FClang compiler (includes libFuzzer)\n- LLVM tools for coverage analysis (optional)\n\n### Linux (Ubuntu\u002FDebian)\n\n```bash\napt install clang llvm\n```\n\nFor the latest LLVM version:\n```bash\n# Add LLVM repository from apt.llvm.org\n# Then install specific version, e.g.:\napt install clang-18 llvm-18\n```\n\n### macOS\n\n```bash\n# Using Homebrew\nbrew install llvm\n\n# Or using Nix\nnix-env -i clang\n```\n\n### Windows\n\nInstall Clang through Visual Studio. Refer to [Microsoft's documentation](https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Fcpp\u002Fbuild\u002Fclang-support-msbuild?view=msvc-170) for setup instructions.\n\n**Recommendation:** If possible, fuzz on a local x86_64 VM or rent one on DigitalOcean, AWS, or Hetzner. Linux provides the best support for libFuzzer.\n\n### Verification\n\n```bash\nclang++ --version\n# Should show LLVM version information\n```\n\n## Writing a Harness\n\n### Harness Structure\n\nThe harness is the entry point for the fuzzer. libFuzzer calls the `LLVMFuzzerTestOneInput` function repeatedly with different inputs.\n\n```c++\n#include \u003Cstdint.h>\n#include \u003Cstddef.h>\n\nextern \"C\" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {\n    \u002F\u002F 1. Optional: Validate input size\n    if (size \u003C MIN_REQUIRED_SIZE) {\n        return 0;  \u002F\u002F Reject inputs that are too small\n    }\n\n    \u002F\u002F 2. Optional: Convert raw bytes to structured data\n    \u002F\u002F Example: Parse two integers from byte array\n    if (size >= 2 * sizeof(uint32_t)) {\n        uint32_t a = *(uint32_t*)(data);\n        uint32_t b = *(uint32_t*)(data + sizeof(uint32_t));\n        my_function(a, b);\n    }\n\n    \u002F\u002F 3. Call target function\n    target_function(data, size);\n\n    \u002F\u002F 4. Always return 0 (non-zero reserved for future use)\n    return 0;\n}\n```\n\n### Harness Rules\n\n| Do | Don't |\n|----|-------|\n| Handle all input types (empty, huge, malformed) | Call `exit()` - stops fuzzing process |\n| Join all threads before returning | Leave threads running |\n| Keep harness fast and simple | Add excessive logging or complexity |\n| Maintain determinism | Use random number generators or read `\u002Fdev\u002Frandom` |\n| Reset global state between runs | Rely on state from previous executions |\n| Use narrow, focused targets | Mix unrelated data formats (PNG + TCP) in one harness |\n\n**Rationale:**\n- **Speed matters:** Aim for 100s-1000s executions per second per core\n- **Reproducibility:** Crashes must be reproducible after fuzzing completes\n- **Isolation:** Each execution should be independent\n\n### Using FuzzedDataProvider for Complex Inputs\n\nFor complex inputs (strings, multiple parameters), use the `FuzzedDataProvider` helper:\n\n```c++\n#include \u003Cstdint.h>\n#include \u003Cstddef.h>\n#include \"FuzzedDataProvider.h\"  \u002F\u002F From LLVM project\n\nextern \"C\" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {\n    FuzzedDataProvider fuzzed_data(data, size);\n\n    \u002F\u002F Extract structured data\n    size_t allocation_size = fuzzed_data.ConsumeIntegral\u003Csize_t>();\n    std::vector\u003Cchar> str1 = fuzzed_data.ConsumeBytesWithTerminator\u003Cchar>(32, 0xFF);\n    std::vector\u003Cchar> str2 = fuzzed_data.ConsumeBytesWithTerminator\u003Cchar>(32, 0xFF);\n\n    \u002F\u002F Call target with extracted data\n    char* result = concat(&str1[0], str1.size(), &str2[0], str2.size(), allocation_size);\n    if (result != NULL) {\n        free(result);\n    }\n\n    return 0;\n}\n```\n\nDownload `FuzzedDataProvider.h` from the [LLVM repository](https:\u002F\u002Fgithub.com\u002Fllvm\u002Fllvm-project\u002Fblob\u002Fmain\u002Fcompiler-rt\u002Finclude\u002Ffuzzer\u002FFuzzedDataProvider.h).\n\n### Interleaved Fuzzing\n\nUse a single harness to test multiple related functions:\n\n```c++\nextern \"C\" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {\n    if (size \u003C 1 + 2 * sizeof(int32_t)) {\n        return 0;\n    }\n\n    uint8_t mode = data[0];\n    int32_t numbers[2];\n    memcpy(numbers, data + 1, 2 * sizeof(int32_t));\n\n    \u002F\u002F Select function based on first byte\n    switch (mode % 4) {\n        case 0: add(numbers[0], numbers[1]); break;\n        case 1: subtract(numbers[0], numbers[1]); break;\n        case 2: multiply(numbers[0], numbers[1]); break;\n        case 3: divide(numbers[0], numbers[1]); break;\n    }\n\n    return 0;\n}\n```\n\n> **See Also:** For detailed harness writing techniques, patterns for handling complex inputs,\n> structure-aware fuzzing, and protobuf-based fuzzing, see the **fuzz-harness-writing** technique skill.\n\n## Compilation\n\n### Basic Compilation\n\nThe key flag is `-fsanitize=fuzzer`, which:\n- Links the libFuzzer runtime (provides `main` function)\n- Enables SanitizerCoverage instrumentation for coverage tracking\n- Disables built-in functions like `memcmp`\n\n```bash\nclang++ -fsanitize=fuzzer -g -O2 harness.cc target.cc -o fuzz\n```\n\n**Flags explained:**\n- `-fsanitize=fuzzer`: Enable libFuzzer\n- `-g`: Add debug symbols (helpful for crash analysis)\n- `-O2`: Production-level optimizations (recommended for fuzzing)\n- `-DNO_MAIN`: Define macro if your code has a `main` function\n\n### With Sanitizers\n\n**AddressSanitizer (recommended):**\n```bash\nclang++ -fsanitize=fuzzer,address -g -O2 -U_FORTIFY_SOURCE harness.cc target.cc -o fuzz\n```\n\n**Multiple sanitizers:**\n```bash\nclang++ -fsanitize=fuzzer,address,undefined -g -O2 harness.cc target.cc -o fuzz\n```\n\n> **See Also:** For detailed sanitizer configuration, common issues, ASAN_OPTIONS flags,\n> and advanced sanitizer usage, see the **address-sanitizer** and **undefined-behavior-sanitizer**\n> technique skills.\n\n### Build Flags\n\n| Flag | Purpose |\n|------|---------|\n| `-fsanitize=fuzzer` | Enable libFuzzer runtime and instrumentation |\n| `-fsanitize=address` | Enable AddressSanitizer (memory error detection) |\n| `-fsanitize=undefined` | Enable UndefinedBehaviorSanitizer |\n| `-fsanitize=fuzzer-no-link` | Instrument without linking fuzzer (for libraries) |\n| `-g` | Include debug symbols |\n| `-O2` | Production optimization level |\n| `-U_FORTIFY_SOURCE` | Disable fortification (can interfere with ASan) |\n\n### Building Static Libraries\n\nFor projects that produce static libraries:\n\n1. Build the library with fuzzing instrumentation:\n```bash\nexport CC=clang CFLAGS=\"-fsanitize=fuzzer-no-link -fsanitize=address\"\nexport CXX=clang++ CXXFLAGS=\"$CFLAGS\"\n.\u002Fconfigure --enable-shared=no\nmake\n```\n\n2. Link the static library with your harness:\n```bash\nclang++ -fsanitize=fuzzer -fsanitize=address harness.cc libmylib.a -o fuzz\n```\n\n### CMake Integration\n\n```cmake\nproject(FuzzTarget)\ncmake_minimum_required(VERSION 3.0)\n\nadd_executable(fuzz main.cc harness.cc)\ntarget_compile_definitions(fuzz PRIVATE NO_MAIN=1)\ntarget_compile_options(fuzz PRIVATE -g -O2 -fsanitize=fuzzer -fsanitize=address)\ntarget_link_libraries(fuzz -fsanitize=fuzzer -fsanitize=address)\n```\n\nBuild with:\n```bash\ncmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .\ncmake --build .\n```\n\n## Corpus Management\n\n### Creating Initial Corpus\n\nCreate a directory for the corpus (can start empty):\n\n```bash\nmkdir corpus\u002F\n```\n\n**Optional but recommended:** Provide seed inputs (valid example files):\n\n```bash\n# For a PNG parser:\ncp examples\u002F*.png corpus\u002F\n\n# For a protocol parser:\ncp test_packets\u002F*.bin corpus\u002F\n```\n\n**Benefits of seed inputs:**\n- Fuzzer doesn't start from scratch\n- Reaches valid code paths faster\n- Significantly improves effectiveness\n\n### Corpus Structure\n\nThe corpus directory contains:\n- Input files that trigger unique code paths\n- Minimized versions (libFuzzer automatically minimizes)\n- Named by content hash (e.g., `a9993e364706816aba3e25717850c26c9cd0d89d`)\n\n### Corpus Minimization\n\nlibFuzzer automatically minimizes corpus entries during fuzzing. To explicitly minimize:\n\n```bash\nmkdir minimized_corpus\u002F\n.\u002Ffuzz -merge=1 minimized_corpus\u002F corpus\u002F\n```\n\nThis creates a deduplicated, minimized corpus in `minimized_corpus\u002F`.\n\n> **See Also:** For corpus creation strategies, seed selection, format-specific corpus building,\n> and corpus maintenance, see the **fuzzing-corpus** technique skill.\n\n## Running Campaigns\n\n### Basic Run\n\n```bash\n.\u002Ffuzz corpus\u002F\n```\n\nThis runs until a crash is found or you stop it (Ctrl+C).\n\n### Recommended: Continue After Crashes\n\n```bash\n.\u002Ffuzz -fork=1 -ignore_crashes=1 corpus\u002F\n```\n\nThe `-fork` and `-ignore_crashes` flags (experimental but widely used) allow fuzzing to continue after finding crashes.\n\n### Common Options\n\n**Control input size:**\n```bash\n.\u002Ffuzz -max_len=4000 corpus\u002F\n```\nRule of thumb: 2x the size of minimal realistic input.\n\n**Set timeout:**\n```bash\n.\u002Ffuzz -timeout=2 corpus\u002F\n```\nAbort test cases that run longer than 2 seconds.\n\n**Use a dictionary:**\n```bash\n.\u002Ffuzz -dict=.\u002Fformat.dict corpus\u002F\n```\n\n**Close stdout\u002Fstderr (speed up fuzzing):**\n```bash\n.\u002Ffuzz -close_fd_mask=3 corpus\u002F\n```\n\n**See all options:**\n```bash\n.\u002Ffuzz -help=1\n```\n\n### Multi-Core Fuzzing\n\n**Option 1: Jobs and workers (recommended):**\n```bash\n.\u002Ffuzz -jobs=4 -workers=4 -fork=1 -ignore_crashes=1 corpus\u002F\n```\n- `-jobs=4`: Run 4 sequential campaigns\n- `-workers=4`: Process jobs in parallel with 4 processes\n- Test cases are shared between jobs\n\n**Option 2: Fork mode:**\n```bash\n.\u002Ffuzz -fork=4 -ignore_crashes=1 corpus\u002F\n```\n\n**Note:** For serious multi-core fuzzing, consider switching to AFL++, Honggfuzz, or LibAFL.\n\n### Re-executing Test Cases\n\n**Re-run a single crash:**\n```bash\n.\u002Ffuzz .\u002Fcrash-a9993e364706816aba3e25717850c26c9cd0d89d\n```\n\n**Test all inputs in a directory without fuzzing:**\n```bash\n.\u002Ffuzz -runs=0 corpus\u002F\n```\n\n### Interpreting Output\n\nWhen fuzzing runs, you'll see statistics like:\n\n```\nINFO: Seed: 3517090860\nINFO: Loaded 1 modules (9 inline 8-bit counters)\n#2      INITED cov: 3 ft: 4 corp: 1\u002F1b exec\u002Fs: 0 rss: 26Mb\n#57     NEW    cov: 4 ft: 5 corp: 2\u002F4b lim: 4 exec\u002Fs: 0 rss: 26Mb\n```\n\n| Output | Meaning |\n|--------|---------|\n| `INITED` | Fuzzing initialized |\n| `NEW` | New coverage found, added to corpus |\n| `REDUCE` | Input minimized while keeping coverage |\n| `cov: N` | Number of coverage edges hit |\n| `corp: X\u002FYb` | Corpus size: X entries, Y total bytes |\n| `exec\u002Fs: N` | Executions per second |\n| `rss: NMb` | Resident memory usage |\n\n**On crash:**\n```\n==11672== ERROR: libFuzzer: deadly signal\nartifact_prefix='.\u002F'; Test unit written to .\u002Fcrash-a9993e364706816aba3e25717850c26c9cd0d89d\n0x61,0x62,0x63,\nabc\nBase64: YWJj\n```\n\nThe crash is saved to `.\u002Fcrash-\u003Chash>` with the input shown in hex, UTF-8, and Base64.\n\n**Reproducibility:** Use `-seed=\u003Cvalue>` to reproduce a fuzzing campaign (single-core only).\n\n## Fuzzing Dictionary\n\nDictionaries help the fuzzer discover interesting inputs faster by providing hints about the input format.\n\n### Dictionary Format\n\nCreate a text file with quoted strings (one per line):\n\n```conf\n# Lines starting with '#' are comments\n\n# Magic bytes\nmagic=\"\\x89PNG\"\nmagic2=\"IEND\"\n\n# Keywords\n\"GET\"\n\"POST\"\n\"Content-Type\"\n\n# Hex sequences\ndelimiter=\"\\xFF\\xD8\\xFF\"\n```\n\n### Using a Dictionary\n\n```bash\n.\u002Ffuzz -dict=.\u002Fformat.dict corpus\u002F\n```\n\n### Generating a Dictionary\n\n**From header files:**\n```bash\ngrep -o '\".*\"' header.h > header.dict\n```\n\n**From man pages:**\n```bash\nman curl | grep -oP '^\\s*(--|-)\\K\\S+' | sed 's\u002F[,.]$\u002F\u002F' | sed 's\u002F^\u002F\"&\u002F; s\u002F$\u002F&\"\u002F' | sort -u > man.dict\n```\n\n**From binary strings:**\n```bash\nstrings .\u002Fbinary | sed 's\u002F^\u002F\"&\u002F; s\u002F$\u002F&\"\u002F' > strings.dict\n```\n\n**Using LLMs:** Ask ChatGPT or similar to generate a dictionary for your format (e.g., \"Generate a libFuzzer dictionary for a JSON parser\").\n\n> **See Also:** For advanced dictionary generation, format-specific dictionaries, and\n> dictionary optimization strategies, see the **fuzzing-dictionaries** technique skill.\n\n## Coverage Analysis\n\nWhile libFuzzer shows basic coverage stats (`cov: N`), detailed coverage analysis requires additional tools.\n\n### Source-Based Coverage\n\n**1. Recompile with coverage instrumentation:**\n```bash\nclang++ -fsanitize=fuzzer -fprofile-instr-generate -fcoverage-mapping harness.cc target.cc -o fuzz\n```\n\n**2. Run fuzzer to collect coverage:**\n```bash\nLLVM_PROFILE_FILE=\"coverage-%p.profraw\" .\u002Ffuzz -runs=10000 corpus\u002F\n```\n\n**3. Merge coverage data:**\n```bash\nllvm-profdata merge -sparse coverage-*.profraw -o coverage.profdata\n```\n\n**4. Generate coverage report:**\n```bash\nllvm-cov show .\u002Ffuzz -instr-profile=coverage.profdata\n```\n\n**5. Generate HTML report:**\n```bash\nllvm-cov show .\u002Ffuzz -instr-profile=coverage.profdata -format=html > coverage.html\n```\n\n### Improving Coverage\n\n**Tips:**\n- Provide better seed inputs in corpus\n- Use dictionaries for format-aware fuzzing\n- Check if harness properly exercises target\n- Consider structure-aware fuzzing for complex formats\n- Run longer campaigns (days\u002Fweeks)\n\n> **See Also:** For detailed coverage analysis techniques, identifying coverage gaps,\n> systematic coverage improvement, and comparing coverage across fuzzers, see the\n> **coverage-analysis** technique skill.\n\n## Sanitizer Integration\n\n### AddressSanitizer (ASan)\n\nASan detects memory errors like buffer overflows and use-after-free bugs. **Highly recommended for fuzzing.**\n\n**Enable ASan:**\n```bash\nclang++ -fsanitize=fuzzer,address -g -O2 -U_FORTIFY_SOURCE harness.cc target.cc -o fuzz\n```\n\n**Example ASan output:**\n```\n==1276163==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000c4ab1\nWRITE of size 1 at 0x6020000c4ab1 thread T0\n    #0 0x55555568631a in check_buf(char*, unsigned long) main.cc:13:25\n    #1 0x5555556860bf in LLVMFuzzerTestOneInput harness.cc:7:3\n```\n\n**Configure ASan with environment variables:**\n```bash\nASAN_OPTIONS=verbosity=1:abort_on_error=1 .\u002Ffuzz corpus\u002F\n```\n\n**Important flags:**\n- `verbosity=1`: Show ASan is active\n- `detect_leaks=0`: Disable leak detection (leaks reported at end)\n- `abort_on_error=1`: Call `abort()` instead of `_exit()` on errors\n\n**Drawbacks:**\n- 2-4x slowdown\n- Requires ~20TB virtual memory (disable memory limits: `-rss_limit_mb=0`)\n- Best supported on Linux\n\n> **See Also:** For comprehensive ASan configuration, common pitfalls, symbolization,\n> and combining with other sanitizers, see the **address-sanitizer** technique skill.\n\n### UndefinedBehaviorSanitizer (UBSan)\n\nUBSan detects undefined behavior like integer overflow, null pointer dereference, etc.\n\n**Enable UBSan:**\n```bash\nclang++ -fsanitize=fuzzer,undefined -g -O2 harness.cc target.cc -o fuzz\n```\n\n**Combine with ASan:**\n```bash\nclang++ -fsanitize=fuzzer,address,undefined -g -O2 harness.cc target.cc -o fuzz\n```\n\n### MemorySanitizer (MSan)\n\nMSan detects uninitialized memory reads. More complex to use (requires rebuilding all dependencies).\n\n```bash\nclang++ -fsanitize=fuzzer,memory -g -O2 harness.cc target.cc -o fuzz\n```\n\n### Common Sanitizer Issues\n\n| Issue | Solution |\n|-------|----------|\n| ASan slows fuzzing too much | Use `-fsanitize-recover=address` for non-fatal errors |\n| Out of memory | Set `ASAN_OPTIONS=rss_limit_mb=0` or `-rss_limit_mb=0` |\n| Stack exhaustion | Increase stack size: `ASAN_OPTIONS=stack_size=8388608` |\n| False positives with `_FORTIFY_SOURCE` | Use `-U_FORTIFY_SOURCE` flag |\n| MSan reports in dependencies | Rebuild all dependencies with `-fsanitize=memory` |\n\n## Real-World Examples\n\n### Example 1: Fuzzing libpng\n\nlibpng is a widely-used library for reading\u002Fwriting PNG images. Bugs can lead to security issues.\n\n**1. Get source code:**\n```bash\ncurl -L -O https:\u002F\u002Fdownloads.sourceforge.net\u002Fproject\u002Flibpng\u002Flibpng16\u002F1.6.37\u002Flibpng-1.6.37.tar.xz\ntar xf libpng-1.6.37.tar.xz\ncd libpng-1.6.37\u002F\n```\n\n**2. Install dependencies:**\n```bash\napt install zlib1g-dev\n```\n\n**3. Compile with fuzzing instrumentation:**\n```bash\nexport CC=clang CFLAGS=\"-fsanitize=fuzzer-no-link -fsanitize=address\"\nexport CXX=clang++ CXXFLAGS=\"$CFLAGS\"\n.\u002Fconfigure --enable-shared=no\nmake\n```\n\n**4. Get a harness (or write your own):**\n```bash\ncurl -O https:\u002F\u002Fraw.githubusercontent.com\u002Fglennrp\u002Flibpng\u002Ff8e5fa92b0e37ab597616f554bee254157998227\u002Fcontrib\u002Foss-fuzz\u002Flibpng_read_fuzzer.cc\n```\n\n**5. Prepare corpus and dictionary:**\n```bash\nmkdir corpus\u002F\ncurl -o corpus\u002Finput.png https:\u002F\u002Fraw.githubusercontent.com\u002Fglennrp\u002Flibpng\u002Facfd50ae0ba3198ad734e5d4dec2b05341e50924\u002Fcontrib\u002Fpngsuite\u002Fiftp1n3p08.png\ncurl -O https:\u002F\u002Fraw.githubusercontent.com\u002Fglennrp\u002Flibpng\u002F2fff013a6935967960a5ae626fc21432807933dd\u002Fcontrib\u002Foss-fuzz\u002Fpng.dict\n```\n\n**6. Link and compile fuzzer:**\n```bash\nclang++ -fsanitize=fuzzer -fsanitize=address libpng_read_fuzzer.cc .libs\u002Flibpng16.a -lz -o fuzz\n```\n\n**7. Run fuzzing campaign:**\n```bash\n.\u002Ffuzz -close_fd_mask=3 -dict=.\u002Fpng.dict corpus\u002F\n```\n\n### Example 2: Simple Division Bug\n\nHarness that finds a division-by-zero bug:\n\n```c++\n#include \u003Cstdint.h>\n#include \u003Cstddef.h>\n\ndouble divide(uint32_t numerator, uint32_t denominator) {\n    \u002F\u002F Bug: No check if denominator is zero\n    return numerator \u002F denominator;\n}\n\nextern \"C\" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {\n    if(size != 2 * sizeof(uint32_t)) {\n        return 0;\n    }\n\n    uint32_t numerator = *(uint32_t*)(data);\n    uint32_t denominator = *(uint32_t*)(data + sizeof(uint32_t));\n\n    divide(numerator, denominator);\n\n    return 0;\n}\n```\n\nCompile and fuzz:\n```bash\nclang++ -fsanitize=fuzzer harness.cc -o fuzz\n.\u002Ffuzz\n```\n\nThe fuzzer will quickly find inputs causing a crash.\n\n## Advanced Usage\n\n### Tips and Tricks\n\n| Tip | Why It Helps |\n|-----|--------------|\n| Start with single-core, switch to AFL++ for multi-core | libFuzzer harnesses work with AFL++ |\n| Use dictionaries for structured formats | 10-100x faster bug discovery |\n| Close file descriptors with `-close_fd_mask=3` | Speed boost if SUT writes output |\n| Set reasonable `-max_len` | Prevents wasted time on huge inputs |\n| Run for days\u002Fweeks, not minutes | Coverage plateaus take time to break |\n| Use seed corpus from test suites | Starts fuzzing from valid inputs |\n\n### Structure-Aware Fuzzing\n\nFor highly structured inputs (e.g., complex protocols, file formats), use libprotobuf-mutator:\n\n- Define input structure using Protocol Buffers\n- libFuzzer mutates protobuf messages (structure-preserving mutations)\n- Harness converts protobuf to native format\n\nSee [structure-aware fuzzing documentation](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffuzzing\u002Fblob\u002Fmaster\u002Fdocs\u002Fstructure-aware-fuzzing.md) for details.\n\n### Custom Mutators\n\nlibFuzzer allows custom mutators for specialized fuzzing:\n\n```c++\nextern \"C\" size_t LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size,\n                                          size_t MaxSize, unsigned int Seed) {\n    \u002F\u002F Custom mutation logic\n    return new_size;\n}\n\nextern \"C\" size_t LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1,\n                                            const uint8_t *Data2, size_t Size2,\n                                            uint8_t *Out, size_t MaxOutSize,\n                                            unsigned int Seed) {\n    \u002F\u002F Custom crossover logic\n    return new_size;\n}\n```\n\n### Performance Tuning\n\n| Setting | Impact |\n|---------|--------|\n| `-close_fd_mask=3` | Closes stdout\u002Fstderr, speeds up fuzzing |\n| `-max_len=\u003Creasonable_size>` | Avoids wasting time on huge inputs |\n| `-timeout=\u003Cseconds>` | Detects hangs, prevents stuck executions |\n| Disable ASan for baseline | 2-4x speed boost (but misses memory bugs) |\n| Use `-jobs` and `-workers` | Limited multi-core support |\n| Run on Linux | Best platform support and performance |\n\n## Troubleshooting\n\n| Problem | Cause | Solution |\n|---------|-------|----------|\n| No crashes found after hours | Poor corpus, low coverage | Add seed inputs, use dictionary, check harness |\n| Very slow executions\u002Fsec (\u003C100) | Target too complex, excessive logging | Optimize target, use `-close_fd_mask=3`, reduce logging |\n| Out of memory | ASan's 20TB virtual memory | Set `-rss_limit_mb=0` to disable RSS limit |\n| Fuzzer stops after first crash | Default behavior | Use `-fork=1 -ignore_crashes=1` to continue |\n| Can't reproduce crash | Non-determinism in harness\u002Ftarget | Remove random number generation, global state |\n| Linking errors with `-fsanitize=fuzzer` | Missing libFuzzer runtime | Ensure using Clang, check LLVM installation |\n| GCC project won't compile with Clang | GCC-specific code | Switch to AFL++ with `gcc_plugin` instead |\n| Coverage not improving | Corpus plateau | Run longer, add dictionary, improve seeds, check coverage report |\n| Crashes but ASan doesn't trigger | Memory error not detected without ASan | Recompile with `-fsanitize=address` |\n\n## Related Skills\n\n### Technique Skills\n\n| Skill | Use Case |\n|-------|----------|\n| **fuzz-harness-writing** | Detailed guidance on writing effective harnesses, structure-aware fuzzing, and FuzzedDataProvider usage |\n| **address-sanitizer** | Memory error detection configuration, ASAN_OPTIONS, and troubleshooting |\n| **undefined-behavior-sanitizer** | Detecting undefined behavior during fuzzing |\n| **coverage-analysis** | Measuring fuzzing effectiveness and identifying untested code paths |\n| **fuzzing-corpus** | Building and managing seed corpora, corpus minimization strategies |\n| **fuzzing-dictionaries** | Creating format-specific dictionaries for faster bug discovery |\n\n### Related Fuzzers\n\n| Skill | When to Consider |\n|-------|------------------|\n| **aflpp** | When you need serious multi-core fuzzing, or when libFuzzer coverage plateaus |\n| **honggfuzz** | When you want hardware-based coverage feedback on Linux |\n| **libafl** | When building custom fuzzers or conducting fuzzing research |\n\n## Resources\n\n### Official Documentation\n\n- [LLVM libFuzzer Documentation](https:\u002F\u002Fllvm.org\u002Fdocs\u002FLibFuzzer.html) - Official reference\n- [libFuzzer Tutorial by Google](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffuzzing\u002Fblob\u002Fmaster\u002Ftutorial\u002FlibFuzzerTutorial.md) - Step-by-step guide\n- [SanitizerCoverage](https:\u002F\u002Fclang.llvm.org\u002Fdocs\u002FSanitizerCoverage.html) - Coverage instrumentation details\n\n### Advanced Topics\n\n- [Structure-Aware Fuzzing with libprotobuf-mutator](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffuzzing\u002Fblob\u002Fmaster\u002Fdocs\u002Fstructure-aware-fuzzing.md)\n- [Split Inputs in libFuzzer](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffuzzing\u002Fblob\u002Fmaster\u002Fdocs\u002Fsplit-inputs.md)\n- [FuzzedDataProvider Header](https:\u002F\u002Fgithub.com\u002Fllvm\u002Fllvm-project\u002Fblob\u002Fmain\u002Fcompiler-rt\u002Finclude\u002Ffuzzer\u002FFuzzedDataProvider.h)\n\n### Example Projects\n\n- [OSS-Fuzz](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Foss-fuzz) - Continuous fuzzing for open-source projects (many libFuzzer examples)\n- [AFL++ Dictionary Collection](https:\u002F\u002Fgithub.com\u002FAFLplusplus\u002FAFLplusplus\u002Ftree\u002Fstable\u002Fdictionaries) - Reusable dictionaries\n","# libFuzzer\n\nlibFuzzer is an in-process, coverage-guided fuzzer that is part of the LLVM project. It's the recommended starting point for fuzzing C\u002FC++ projects due to its simplicity and integration with the LLVM toolchain. While libFuzzer has been in maintenance-only mode since late 2022, it is easier to install and use than its alternatives, has wide support, and will be maintained for the foreseeable future.\n\n## When to Use\n\n| Fuzzer | Best For | Complexity |\n|--------|----------|------------|\n| libFuzzer | Quick setup, single-project fuzzing | Low |\n| AFL++ | Multi-core fuzzing, diverse mutations | Medium |\n| LibAFL | Custom fuzzers, research projects | High |\n| Honggfuzz | Hardware-based coverage | Medium |\n\n**Choose libFuzzer when:**\n- You need a simple, quick setup for C\u002FC++ code\n- Project uses Clang for compilation\n- Single-core fuzzing is sufficient initially\n- Transitioning to AFL++ later is an option (harnesses are compatible)\n\n**Note:** Fuzzing harnesses written for libFuzzer are compatible with AFL++, making it easy to transition if you need more advanced features like better multi-core support.\n\n## Quick Start\n\n```c++\n#include \u003Cstdint.h>\n#include \u003Cstddef.h>\n\nextern \"C\" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {\n    \u002F\u002F Validate input if needed\n    if (size \u003C 1) return 0;\n\n    \u002F\u002F Call your target function with fuzzer-provided data\n    my_target_function(data, size);\n\n    return 0;\n}\n```\n\nCompile and run:\n```bash\nclang++ -fsanitize=fuzzer,address -g -O2 harness.cc target.cc -o fuzz\nmkdir corpus\u002F\n.\u002Ffuzz corpus\u002F\n```\n\n## Installation\n\n### Prerequisites\n\n- LLVM\u002FClang compiler (includes libFuzzer)\n- LLVM tools for coverage analysis (optional)\n\n### Linux (Ubuntu\u002FDebian)\n\n```bash\napt install clang llvm\n```\n\nFor the latest LLVM version:\n```bash\n# Add LLVM repository from apt.llvm.org\n# Then install specific version, e.g.:\napt install clang-18 llvm-18\n```\n\n### macOS\n\n```bash\n# Using Homebrew\nbrew install llvm\n\n# Or using Nix\nnix-env -i clang\n```\n\n### Windows\n\nInstall Clang through Visual Studio. Refer to [Microsoft's documentation](https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Fcpp\u002Fbuild\u002Fclang-support-msbuild?view=msvc-170) for setup instructions.\n\n**Recommendation:** If possible, fuzz on a local x86_64 VM or rent one on DigitalOcean, AWS, or Hetzner. Linux provides the best support for libFuzzer.\n\n### Verification\n\n```bash\nclang++ --version\n# Should show LLVM version information\n```\n\n## Writing a Harness\n\n### Harness Structure\n\nThe harness is the entry point for the fuzzer. libFuzzer calls the `LLVMFuzzerTestOneInput` function repeatedly with different inputs.\n\n```c++\n#include \u003Cstdint.h>\n#include \u003Cstddef.h>\n\nextern \"C\" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {\n    \u002F\u002F 1. Optional: Validate input size\n    if (size \u003C MIN_REQUIRED_SIZE) {\n        return 0;  \u002F\u002F Reject inputs that are too small\n    }\n\n    \u002F\u002F 2. Optional: Convert raw bytes to structured data\n    \u002F\u002F Example: Parse two integers from byte array\n    if (size >= 2 * sizeof(uint32_t)) {\n        uint32_t a = *(uint32_t*)(data);\n        uint32_t b = *(uint32_t*)(data + sizeof(uint32_t));\n        my_function(a, b);\n    }\n\n    \u002F\u002F 3. Call target function\n    target_function(data, size);\n\n    \u002F\u002F 4. Always return 0 (non-zero reserved for future use)\n    return 0;\n}\n```\n\n### Harness Rules\n\n| Do | Don't |\n|----|-------|\n| Handle all input types (empty, huge, malformed) | Call `exit()` - stops fuzzing process |\n| Join all threads before returning | Leave threads running |\n| Keep harness fast and simple | Add excessive logging or complexity |\n| Maintain determinism | Use random number generators or read `\u002Fdev\u002Frandom` |\n| Reset global state between runs | Rely on state from previous executions |\n| Use narrow, focused targets | Mix unrelated data formats (PNG + TCP) in one harness |\n\n**Rationale:**\n- **Speed matters:** Aim for 100s-1000s executions per second per core\n- **Reproducibility:** Crashes must be reproducible after fuzzing completes\n- **Isolation:** Each execution should be independent\n\n### Using FuzzedDataProvider for Complex Inputs\n\nFor complex inputs (strings, multiple parameters), use the `FuzzedDataProvider` helper:\n\n```c++\n#include \u003Cstdint.h>\n#include \u003Cstddef.h>\n#include \"FuzzedDataProvider.h\"  \u002F\u002F From LLVM project\n\nextern \"C\" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {\n    FuzzedDataProvider fuzzed_data(data, size);\n\n    \u002F\u002F Extract structured data\n    size_t allocation_size = fuzzed_data.ConsumeIntegral\u003Csize_t>();\n    std::vector\u003Cchar> str1 = fuzzed_data.ConsumeBytesWithTerminator\u003Cchar>(32, 0xFF);\n    std::vector\u003Cchar> str2 = fuzzed_data.ConsumeBytesWithTerminator\u003Cchar>(32, 0xFF);\n\n    \u002F\u002F Call target with extracted data\n    char* result = concat(&str1[0], str1.size(), &str2[0], str2.size(), allocation_size);\n    if (result != NULL) {\n        free(result);\n    }\n\n    return 0;\n}\n```\n\nDownload `FuzzedDataProvider.h` from the [LLVM repository](https:\u002F\u002Fgithub.com\u002Fllvm\u002Fllvm-project\u002Fblob\u002Fmain\u002Fcompiler-rt\u002Finclude\u002Ffuzzer\u002FFuzzedDataProvider.h).\n\n### Interleaved Fuzzing\n\nUse a single harness to test multiple related functions:\n\n```c++\nextern \"C\" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {\n    if (size \u003C 1 + 2 * sizeof(int32_t)) {\n        return 0;\n    }\n\n    uint8_t mode = data[0];\n    int32_t numbers[2];\n    memcpy(numbers, data + 1, 2 * sizeof(int32_t));\n\n    \u002F\u002F Select function based on first byte\n    switch (mode % 4) {\n        case 0: add(numbers[0], numbers[1]); break;\n        case 1: subtract(numbers[0], numbers[1]); break;\n        case 2: multiply(numbers[0], numbers[1]); break;\n        case 3: divide(numbers[0], numbers[1]); break;\n    }\n\n    return 0;\n}\n```\n\n> **See Also:** For detailed harness writing techniques, patterns for handling complex inputs,\n> structure-aware fuzzing, and protobuf-based fuzzing, see the **fuzz-harness-writing** technique skill.\n\n## Compilation\n\n### Basic Compilation\n\nThe key flag is `-fsanitize=fuzzer`, which:\n- Links the libFuzzer runtime (provides `main` function)\n- Enables SanitizerCoverage instrumentation for coverage tracking\n- Disables built-in functions like `memcmp`\n\n```bash\nclang++ -fsanitize=fuzzer -g -O2 harness.cc target.cc -o fuzz\n```\n\n**Flags explained:**\n- `-fsanitize=fuzzer`: Enable libFuzzer\n- `-g`: Add debug symbols (helpful for crash analysis)\n- `-O2`: Production-level optimizations (recommended for fuzzing)\n- `-DNO_MAIN`: Define macro if your code has a `main` function\n\n### With Sanitizers\n\n**AddressSanitizer (recommended):**\n```bash\nclang++ -fsanitize=fuzzer,address -g -O2 -U_FORTIFY_SOURCE harness.cc target.cc -o fuzz\n```\n\n**Multiple sanitizers:**\n```bash\nclang++ -fsanitize=fuzzer,address,undefined -g -O2 harness.cc target.cc -o fuzz\n```\n\n> **See Also:** For detailed sanitizer configuration, common issues, ASAN_OPTIONS flags,\n> and advanced sanitizer usage, see the **address-sanitizer** and **undefined-behavior-sanitizer**\n> technique skills.\n\n### Build Flags\n\n| Flag | Purpose |\n|------|---------|\n| `-fsanitize=fuzzer` | Enable libFuzzer runtime and instrumentation |\n| `-fsanitize=address` | Enable AddressSanitizer (memory error detection) |\n| `-fsanitize=undefined` | Enable UndefinedBehaviorSanitizer |\n| `-fsanitize=fuzzer-no-link` | Instrument without linking fuzzer (for libraries) |\n| `-g` | Include debug symbols |\n| `-O2` | Production optimization level |\n| `-U_FORTIFY_SOURCE` | Disable fortification (can interfere with ASan) |\n\n### Building Static Libraries\n\nFor projects that produce static libraries:\n\n1. Build the library with fuzzing instrumentation:\n```bash\nexport CC=clang CFLAGS=\"-fsanitize=fuzzer-no-link -fsanitize=address\"\nexport CXX=clang++ CXXFLAGS=\"$CFLAGS\"\n.\u002Fconfigure --enable-shared=no\nmake\n```\n\n2. Link the static library with your harness:\n```bash\nclang++ -fsanitize=fuzzer -fsanitize=address harness.cc libmylib.a -o fuzz\n```\n\n### CMake Integration\n\n```cmake\nproject(FuzzTarget)\ncmake_minimum_required(VERSION 3.0)\n\nadd_executable(fuzz main.cc harness.cc)\ntarget_compile_definitions(fuzz PRIVATE NO_MAIN=1)\ntarget_compile_options(fuzz PRIVATE -g -O2 -fsanitize=fuzzer -fsanitize=address)\ntarget_link_libraries(fuzz -fsanitize=fuzzer -fsanitize=address)\n```\n\nBuild with:\n```bash\ncmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .\ncmake --build .\n```\n\n## Corpus Management\n\n### Creating Initial Corpus\n\nCreate a directory for the corpus (can start empty):\n\n```bash\nmkdir corpus\u002F\n```\n\n**Optional but recommended:** Provide seed inputs (valid example files):\n\n```bash\n# For a PNG parser:\ncp examples\u002F*.png corpus\u002F\n\n# For a protocol parser:\ncp test_packets\u002F*.bin corpus\u002F\n```\n\n**Benefits of seed inputs:**\n- Fuzzer doesn't start from scratch\n- Reaches valid code paths faster\n- Significantly improves effectiveness\n\n### Corpus Structure\n\nThe corpus directory contains:\n- Input files that trigger unique code paths\n- Minimized versions (libFuzzer automatically minimizes)\n- Named by content hash (e.g., `a9993e364706816aba3e25717850c26c9cd0d89d`)\n\n### Corpus Minimization\n\nlibFuzzer automatically minimizes corpus entries during fuzzing. To explicitly minimize:\n\n```bash\nmkdir minimized_corpus\u002F\n.\u002Ffuzz -merge=1 minimized_corpus\u002F corpus\u002F\n```\n\nThis creates a deduplicated, minimized corpus in `minimized_corpus\u002F`.\n\n> **See Also:** For corpus creation strategies, seed selection, format-specific corpus building,\n> and corpus maintenance, see the **fuzzing-corpus** technique skill.\n\n## Running Campaigns\n\n### Basic Run\n\n```bash\n.\u002Ffuzz corpus\u002F\n```\n\nThis runs until a crash is found or you stop it (Ctrl+C).\n\n### Recommended: Continue After Crashes\n\n```bash\n.\u002Ffuzz -fork=1 -ignore_crashes=1 corpus\u002F\n```\n\nThe `-fork` and `-ignore_crashes` flags (experimental but widely used) allow fuzzing to continue after finding crashes.\n\n### Common Options\n\n**Control input size:**\n```bash\n.\u002Ffuzz -max_len=4000 corpus\u002F\n```\nRule of thumb: 2x the size of minimal realistic input.\n\n**Set timeout:**\n```bash\n.\u002Ffuzz -timeout=2 corpus\u002F\n```\nAbort test cases that run longer than 2 seconds.\n\n**Use a dictionary:**\n```bash\n.\u002Ffuzz -dict=.\u002Fformat.dict corpus\u002F\n```\n\n**Close stdout\u002Fstderr (speed up fuzzing):**\n```bash\n.\u002Ffuzz -close_fd_mask=3 corpus\u002F\n```\n\n**See all options:**\n```bash\n.\u002Ffuzz -help=1\n```\n\n### Multi-Core Fuzzing\n\n**Option 1: Jobs and workers (recommended):**\n```bash\n.\u002Ffuzz -jobs=4 -workers=4 -fork=1 -ignore_crashes=1 corpus\u002F\n```\n- `-jobs=4`: Run 4 sequential campaigns\n- `-workers=4`: Process jobs in parallel with 4 processes\n- Test cases are shared between jobs\n\n**Option 2: Fork mode:**\n```bash\n.\u002Ffuzz -fork=4 -ignore_crashes=1 corpus\u002F\n```\n\n**Note:** For serious multi-core fuzzing, consider switching to AFL++, Honggfuzz, or LibAFL.\n\n### Re-executing Test Cases\n\n**Re-run a single crash:**\n```bash\n.\u002Ffuzz .\u002Fcrash-a9993e364706816aba3e25717850c26c9cd0d89d\n```\n\n**Test all inputs in a directory without fuzzing:**\n```bash\n.\u002Ffuzz -runs=0 corpus\u002F\n```\n\n### Interpreting Output\n\nWhen fuzzing runs, you'll see statistics like:\n\n```\nINFO: Seed: 3517090860\nINFO: Loaded 1 modules (9 inline 8-bit counters)\n#2      INITED cov: 3 ft: 4 corp: 1\u002F1b exec\u002Fs: 0 rss: 26Mb\n#57     NEW    cov: 4 ft: 5 corp: 2\u002F4b lim: 4 exec\u002Fs: 0 rss: 26Mb\n```\n\n| Output | Meaning |\n|--------|---------|\n| `INITED` | Fuzzing initialized |\n| `NEW` | New coverage found, added to corpus |\n| `REDUCE` | Input minimized while keeping coverage |\n| `cov: N` | Number of coverage edges hit |\n| `corp: X\u002FYb` | Corpus size: X entries, Y total bytes |\n| `exec\u002Fs: N` | Executions per second |\n| `rss: NMb` | Resident memory usage |\n\n**On crash:**\n```\n==11672== ERROR: libFuzzer: deadly signal\nartifact_prefix='.\u002F'; Test unit written to .\u002Fcrash-a9993e364706816aba3e25717850c26c9cd0d89d\n0x61,0x62,0x63,\nabc\nBase64: YWJj\n```\n\nThe crash is saved to `.\u002Fcrash-\u003Chash>` with the input shown in hex, UTF-8, and Base64.\n\n**Reproducibility:** Use `-seed=\u003Cvalue>` to reproduce a fuzzing campaign (single-core only).\n\n## Fuzzing Dictionary\n\nDictionaries help the fuzzer discover interesting inputs faster by providing hints about the input format.\n\n### Dictionary Format\n\nCreate a text file with quoted strings (one per line):\n\n```conf\n# Lines starting with '#' are comments\n\n# Magic bytes\nmagic=\"\\x89PNG\"\nmagic2=\"IEND\"\n\n# Keywords\n\"GET\"\n\"POST\"\n\"Content-Type\"\n\n# Hex sequences\ndelimiter=\"\\xFF\\xD8\\xFF\"\n```\n\n### Using a Dictionary\n\n```bash\n.\u002Ffuzz -dict=.\u002Fformat.dict corpus\u002F\n```\n\n### Generating a Dictionary\n\n**From header files:**\n```bash\ngrep -o '\".*\"' header.h > header.dict\n```\n\n**From man pages:**\n```bash\nman curl | grep -oP '^\\s*(--|-)\\K\\S+' | sed 's\u002F[,.]$\u002F\u002F' | sed 's\u002F^\u002F\"&\u002F; s\u002F$\u002F&\"\u002F' | sort -u > man.dict\n```\n\n**From binary strings:**\n```bash\nstrings .\u002Fbinary | sed 's\u002F^\u002F\"&\u002F; s\u002F$\u002F&\"\u002F' > strings.dict\n```\n\n**Using LLMs:** Ask ChatGPT or similar to generate a dictionary for your format (e.g., \"Generate a libFuzzer dictionary for a JSON parser\").\n\n> **See Also:** For advanced dictionary generation, format-specific dictionaries, and\n> dictionary optimization strategies, see the **fuzzing-dictionaries** technique skill.\n\n## Coverage Analysis\n\nWhile libFuzzer shows basic coverage stats (`cov: N`), detailed coverage analysis requires additional tools.\n\n### Source-Based Coverage\n\n**1. Recompile with coverage instrumentation:**\n```bash\nclang++ -fsanitize=fuzzer -fprofile-instr-generate -fcoverage-mapping harness.cc target.cc -o fuzz\n```\n\n**2. Run fuzzer to collect coverage:**\n```bash\nLLVM_PROFILE_FILE=\"coverage-%p.profraw\" .\u002Ffuzz -runs=10000 corpus\u002F\n```\n\n**3. Merge coverage data:**\n```bash\nllvm-profdata merge -sparse coverage-*.profraw -o coverage.profdata\n```\n\n**4. Generate coverage report:**\n```bash\nllvm-cov show .\u002Ffuzz -instr-profile=coverage.profdata\n```\n\n**5. Generate HTML report:**\n```bash\nllvm-cov show .\u002Ffuzz -instr-profile=coverage.profdata -format=html > coverage.html\n```\n\n### Improving Coverage\n\n**Tips:**\n- Provide better seed inputs in corpus\n- Use dictionaries for format-aware fuzzing\n- Check if harness properly exercises target\n- Consider structure-aware fuzzing for complex formats\n- Run longer campaigns (days\u002Fweeks)\n\n> **See Also:** For detailed coverage analysis techniques, identifying coverage gaps,\n> systematic coverage improvement, and comparing coverage across fuzzers, see the\n> **coverage-analysis** technique skill.\n\n## Sanitizer Integration\n\n### AddressSanitizer (ASan)\n\nASan detects memory errors like buffer overflows and use-after-free bugs. **Highly recommended for fuzzing.**\n\n**Enable ASan:**\n```bash\nclang++ -fsanitize=fuzzer,address -g -O2 -U_FORTIFY_SOURCE harness.cc target.cc -o fuzz\n```\n\n**Example ASan output:**\n```\n==1276163==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000c4ab1\nWRITE of size 1 at 0x6020000c4ab1 thread T0\n    #0 0x55555568631a in check_buf(char*, unsigned long) main.cc:13:25\n    #1 0x5555556860bf in LLVMFuzzerTestOneInput harness.cc:7:3\n```\n\n**Configure ASan with environment variables:**\n```bash\nASAN_OPTIONS=verbosity=1:abort_on_error=1 .\u002Ffuzz corpus\u002F\n```\n\n**Important flags:**\n- `verbosity=1`: Show ASan is active\n- `detect_leaks=0`: Disable leak detection (leaks reported at end)\n- `abort_on_error=1`: Call `abort()` instead of `_exit()` on errors\n\n**Drawbacks:**\n- 2-4x slowdown\n- Requires ~20TB virtual memory (disable memory limits: `-rss_limit_mb=0`)\n- Best supported on Linux\n\n> **See Also:** For comprehensive ASan configuration, common pitfalls, symbolization,\n> and combining with other sanitizers, see the **address-sanitizer** technique skill.\n\n### UndefinedBehaviorSanitizer (UBSan)\n\nUBSan detects undefined behavior like integer overflow, null pointer dereference, etc.\n\n**Enable UBSan:**\n```bash\nclang++ -fsanitize=fuzzer,undefined -g -O2 harness.cc target.cc -o fuzz\n```\n\n**Combine with ASan:**\n```bash\nclang++ -fsanitize=fuzzer,address,undefined -g -O2 harness.cc target.cc -o fuzz\n```\n\n### MemorySanitizer (MSan)\n\nMSan detects uninitialized memory reads. More complex to use (requires rebuilding all dependencies).\n\n```bash\nclang++ -fsanitize=fuzzer,memory -g -O2 harness.cc target.cc -o fuzz\n```\n\n### Common Sanitizer Issues\n\n| Issue | Solution |\n|-------|----------|\n| ASan slows fuzzing too much | Use `-fsanitize-recover=address` for non-fatal errors |\n| Out of memory | Set `ASAN_OPTIONS=rss_limit_mb=0` or `-rss_limit_mb=0` |\n| Stack exhaustion | Increase stack size: `ASAN_OPTIONS=stack_size=8388608` |\n| False positives with `_FORTIFY_SOURCE` | Use `-U_FORTIFY_SOURCE` flag |\n| MSan reports in dependencies | Rebuild all dependencies with `-fsanitize=memory` |\n\n## Real-World Examples\n\n### Example 1: Fuzzing libpng\n\nlibpng is a widely-used library for reading\u002Fwriting PNG images. Bugs can lead to security issues.\n\n**1. Get source code:**\n```bash\ncurl -L -O https:\u002F\u002Fdownloads.sourceforge.net\u002Fproject\u002Flibpng\u002Flibpng16\u002F1.6.37\u002Flibpng-1.6.37.tar.xz\ntar xf libpng-1.6.37.tar.xz\ncd libpng-1.6.37\u002F\n```\n\n**2. Install dependencies:**\n```bash\napt install zlib1g-dev\n```\n\n**3. Compile with fuzzing instrumentation:**\n```bash\nexport CC=clang CFLAGS=\"-fsanitize=fuzzer-no-link -fsanitize=address\"\nexport CXX=clang++ CXXFLAGS=\"$CFLAGS\"\n.\u002Fconfigure --enable-shared=no\nmake\n```\n\n**4. Get a harness (or write your own):**\n```bash\ncurl -O https:\u002F\u002Fraw.githubusercontent.com\u002Fglennrp\u002Flibpng\u002Ff8e5fa92b0e37ab597616f554bee254157998227\u002Fcontrib\u002Foss-fuzz\u002Flibpng_read_fuzzer.cc\n```\n\n**5. Prepare corpus and dictionary:**\n```bash\nmkdir corpus\u002F\ncurl -o corpus\u002Finput.png https:\u002F\u002Fraw.githubusercontent.com\u002Fglennrp\u002Flibpng\u002Facfd50ae0ba3198ad734e5d4dec2b05341e50924\u002Fcontrib\u002Fpngsuite\u002Fiftp1n3p08.png\ncurl -O https:\u002F\u002Fraw.githubusercontent.com\u002Fglennrp\u002Flibpng\u002F2fff013a6935967960a5ae626fc21432807933dd\u002Fcontrib\u002Foss-fuzz\u002Fpng.dict\n```\n\n**6. Link and compile fuzzer:**\n```bash\nclang++ -fsanitize=fuzzer -fsanitize=address libpng_read_fuzzer.cc .libs\u002Flibpng16.a -lz -o fuzz\n```\n\n**7. Run fuzzing campaign:**\n```bash\n.\u002Ffuzz -close_fd_mask=3 -dict=.\u002Fpng.dict corpus\u002F\n```\n\n### Example 2: Simple Division Bug\n\nHarness that finds a division-by-zero bug:\n\n```c++\n#include \u003Cstdint.h>\n#include \u003Cstddef.h>\n\ndouble divide(uint32_t numerator, uint32_t denominator) {\n    \u002F\u002F Bug: No check if denominator is zero\n    return numerator \u002F denominator;\n}\n\nextern \"C\" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {\n    if(size != 2 * sizeof(uint32_t)) {\n        return 0;\n    }\n\n    uint32_t numerator = *(uint32_t*)(data);\n    uint32_t denominator = *(uint32_t*)(data + sizeof(uint32_t));\n\n    divide(numerator, denominator);\n\n    return 0;\n}\n```\n\nCompile and fuzz:\n```bash\nclang++ -fsanitize=fuzzer harness.cc -o fuzz\n.\u002Ffuzz\n```\n\nThe fuzzer will quickly find inputs causing a crash.\n\n## Advanced Usage\n\n### Tips and Tricks\n\n| Tip | Why It Helps |\n|-----|--------------|\n| Start with single-core, switch to AFL++ for multi-core | libFuzzer harnesses work with AFL++ |\n| Use dictionaries for structured formats | 10-100x faster bug discovery |\n| Close file descriptors with `-close_fd_mask=3` | Speed boost if SUT writes output |\n| Set reasonable `-max_len` | Prevents wasted time on huge inputs |\n| Run for days\u002Fweeks, not minutes | Coverage plateaus take time to break |\n| Use seed corpus from test suites | Starts fuzzing from valid inputs |\n\n### Structure-Aware Fuzzing\n\nFor highly structured inputs (e.g., complex protocols, file formats), use libprotobuf-mutator:\n\n- Define input structure using Protocol Buffers\n- libFuzzer mutates protobuf messages (structure-preserving mutations)\n- Harness converts protobuf to native format\n\nSee [structure-aware fuzzing documentation](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffuzzing\u002Fblob\u002Fmaster\u002Fdocs\u002Fstructure-aware-fuzzing.md) for details.\n\n### Custom Mutators\n\nlibFuzzer allows custom mutators for specialized fuzzing:\n\n```c++\nextern \"C\" size_t LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size,\n                                          size_t MaxSize, unsigned int Seed) {\n    \u002F\u002F Custom mutation logic\n    return new_size;\n}\n\nextern \"C\" size_t LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1,\n                                            const uint8_t *Data2, size_t Size2,\n                                            uint8_t *Out, size_t MaxOutSize,\n                                            unsigned int Seed) {\n    \u002F\u002F Custom crossover logic\n    return new_size;\n}\n```\n\n### Performance Tuning\n\n| Setting | Impact |\n|---------|--------|\n| `-close_fd_mask=3` | Closes stdout\u002Fstderr, speeds up fuzzing |\n| `-max_len=\u003Creasonable_size>` | Avoids wasting time on huge inputs |\n| `-timeout=\u003Cseconds>` | Detects hangs, prevents stuck executions |\n| Disable ASan for baseline | 2-4x speed boost (but misses memory bugs) |\n| Use `-jobs` and `-workers` | Limited multi-core support |\n| Run on Linux | Best platform support and performance |\n\n## Troubleshooting\n\n| Problem | Cause | Solution |\n|---------|-------|----------|\n| No crashes found after hours | Poor corpus, low coverage | Add seed inputs, use dictionary, check harness |\n| Very slow executions\u002Fsec (\u003C100) | Target too complex, excessive logging | Optimize target, use `-close_fd_mask=3`, reduce logging |\n| Out of memory | ASan's 20TB virtual memory | Set `-rss_limit_mb=0` to disable RSS limit |\n| Fuzzer stops after first crash | Default behavior | Use `-fork=1 -ignore_crashes=1` to continue |\n| Can't reproduce crash | Non-determinism in harness\u002Ftarget | Remove random number generation, global state |\n| Linking errors with `-fsanitize=fuzzer` | Missing libFuzzer runtime | Ensure using Clang, check LLVM installation |\n| GCC project won't compile with Clang | GCC-specific code | Switch to AFL++ with `gcc_plugin` instead |\n| Coverage not improving | Corpus plateau | Run longer, add dictionary, improve seeds, check coverage report |\n| Crashes but ASan doesn't trigger | Memory error not detected without ASan | Recompile with `-fsanitize=address` |\n\n## Related Skills\n\n### Technique Skills\n\n| Skill | Use Case |\n|-------|----------|\n| **fuzz-harness-writing** | Detailed guidance on writing effective harnesses, structure-aware fuzzing, and FuzzedDataProvider usage |\n| **address-sanitizer** | Memory error detection configuration, ASAN_OPTIONS, and troubleshooting |\n| **undefined-behavior-sanitizer** | Detecting undefined behavior during fuzzing |\n| **coverage-analysis** | Measuring fuzzing effectiveness and identifying untested code paths |\n| **fuzzing-corpus** | Building and managing seed corpora, corpus minimization strategies |\n| **fuzzing-dictionaries** | Creating format-specific dictionaries for faster bug discovery |\n\n### Related Fuzzers\n\n| Skill | When to Consider |\n|-------|------------------|\n| **aflpp** | When you need serious multi-core fuzzing, or when libFuzzer coverage plateaus |\n| **honggfuzz** | When you want hardware-based coverage feedback on Linux |\n| **libafl** | When building custom fuzzers or conducting fuzzing research |\n\n## Resources\n\n### Official Documentation\n\n- [LLVM libFuzzer Documentation](https:\u002F\u002Fllvm.org\u002Fdocs\u002FLibFuzzer.html) - Official reference\n- [libFuzzer Tutorial by Google](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffuzzing\u002Fblob\u002Fmaster\u002Ftutorial\u002FlibFuzzerTutorial.md) - Step-by-step guide\n- [SanitizerCoverage](https:\u002F\u002Fclang.llvm.org\u002Fdocs\u002FSanitizerCoverage.html) - Coverage instrumentation details\n\n### Advanced Topics\n\n- [Structure-Aware Fuzzing with libprotobuf-mutator](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffuzzing\u002Fblob\u002Fmaster\u002Fdocs\u002Fstructure-aware-fuzzing.md)\n- [Split Inputs in libFuzzer](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffuzzing\u002Fblob\u002Fmaster\u002Fdocs\u002Fsplit-inputs.md)\n- [FuzzedDataProvider Header](https:\u002F\u002Fgithub.com\u002Fllvm\u002Fllvm-project\u002Fblob\u002Fmain\u002Fcompiler-rt\u002Finclude\u002Ffuzzer\u002FFuzzedDataProvider.h)\n\n### Example Projects\n\n- [OSS-Fuzz](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Foss-fuzz) - Continuous fuzzing for open-source projects (many libFuzzer examples)\n- [AFL++ Dictionary Collection](https:\u002F\u002Fgithub.com\u002FAFLplusplus\u002FAFLplusplus\u002Ftree\u002Fstable\u002Fdictionaries) - Reusable dictionaries\n",{"name":5,"type":23,"description":7},"fuzzer","main","f37de8f681f0c0ca0e0ebab6e5fddf764ca7553d","skills\u002Flibfuzzer",1,"https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one","https:\u002F\u002Fagisota.github.io\u002Fold-one\u002F","https:\u002F\u002Fgithub.com\u002Fagisota","pzd.world","2026-07-04 22:32:06",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add agisota\u002Fold-one --skill libfuzzer",{"tool":39,"command":40},"bunx","bunx skills add agisota\u002Fold-one --skill libfuzzer",{"tool":42,"command":43},"pnpm","pnpm dlx skills add agisota\u002Fold-one --skill libfuzzer","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Flibfuzzer\u002FSKILL.md",true,[],[48,55,62,71,78,85],{"skillNo":49,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":54,"publishedAt":18},"01M75KRGZWQWE9JDBS6RX42NWV","zoom-out","Tell the agent to zoom out and give broader context or a higher-level perspective. Use when you're unfamiliar with a section of code or need to understand how it fits into the bigger picture.","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fzoom-out\u002FSKILL.md",[],[],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":18},"01M75KRCZHKE0ZYAQFFYHS0YNP","zeroize-audit","Detects missing zeroization of sensitive data in source code and identifies zeroization removed by compiler optimizations, with assembly-level analysis, and control-flow verification. Use for auditing C\u002FC++\u002FRust code handling secrets, keys, passwords, or other sensitive data.","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fzeroize-audit\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":66,"licenseFileUrl":67,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":18},"01M75KR94KYQ30DTE1P9WNDAE0","yeet","Use only when the user explicitly asks to stage, commit, push, and open a GitHub pull request in one flow using the GitHub CLI (`gh`).","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fyeet\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fyeet\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":18},"01M75KR3H13YJ9QHMD49818FA1","yara-rule-authoring","Guides authoring of high-quality YARA-X detection rules for malware identification. Use when writing, reviewing, or optimizing YARA rules. Covers naming conventions, string selection, performance optimization, migration from legacy YARA, and false positive reduction. Triggers on: YARA, YARA-X, malware detection, threat hunting, IOC, signature, crx module, dex module.","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fyara-rule-authoring\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":18},"01M75KQMPY8A4Y8XTDD2DT0M9T","x-twitter-growth","X\u002FTwitter growth engine for building audience, crafting viral content, and analyzing engagement. Use when the user wants to grow on X\u002FTwitter, write tweets or threads, analyze their X profile, research competitors on X, plan a posting strategy, or optimize engagement. Complements social-content (generic multi-platform) with X-specific depth: algorithm mechanics, thread engineering, reply strategy, profile optimization, and competitive intelligence via web search.","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fx-twitter-growth\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":18},"01M75KQHNZ0ANZNJGZY6M8MDAK","x-api","X\u002FTwitter API integration for posting tweets, threads, reading timelines, search, and analytics. Covers OAuth auth patterns, rate limits, and platform-native content posting. Use when the user wants to interact with X programmatically.","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fx-api\u002FSKILL.md",[],[]]