When the LLM writes the fuzzer: STITCH vs libFuzzer on three C/C++ libraries

Animated STITCH fuzzing run on jsoncpp 1.9.6, with LibAFL statistics and crash objectives increasing
A live five-minute STITCH fuzzing run on jsoncpp 1.9.6.

TL;DR: We investigated a newly published technique that uses an LLM to generate fuzzers for sequences of API calls. Across jsoncpp, libxml2 and rlottie, it reached code that existing libFuzzer harnesses missed, including jsoncpp’s legacy Json::Reader and a known use-after-free. But it ran far slower, and its results depended heavily on the generated specification: some omitted important input paths or introduced false crashes. Our conclusion is that LLM-generated harnesses can complement conventional fuzzing, not replace it; reviewing the generated code and replaying every crash remain essential.


A recent paper by Harrison Green, Fraser Brown, and Claire Le Goues introduced STITCH, a novel fuzzing technique in which an LLM reads a C/C++ library and writes a typed specification of its API. The resulting fuzzer explores sequences of API calls rather than only mutating input bytes for a fixed entry point. We investigated how well that idea works in practice: we reproduced it on three libraries, tested both their latest and known-vulnerable versions, and compared it with libFuzzer under the same compiler, CPU budget and crash-triage process. Beyond execution counts, we measured source coverage, API reach, reproducible findings, false positives and model cost.

Paper: STITCH (arXiv 2602.18689) · Tool: github.com/hgarrereyn/STITCH

The technique we investigated

A classic fuzzer such as libFuzzer needs a person to write a harness: a function that takes bytes and feeds them to one or two library entry points. Everything the harness does not call stays unfuzzed. STITCH replaces the hand-written harness with a specification that an LLM writes from the library's headers and source. The specification lists the library's objects (types such as Json::Value or xmlDocPtr), and for each API function an endpoint: a short C++ snippet that takes typed objects in, calls the function, and hands typed objects out.

The fuzzer then builds call graphs out of endpoints. One test case is a small program: create a parser, feed it a fuzzed string, take the resulting document, query a node, free the document, and so on. Mutations add, remove and splice calls and change their parameters. Two details keep the graphs meaningful:

  • Typed inputs and outputs. An endpoint that needs a xmlDocPtr can only be wired to something that produced one, so most generated programs are well-formed.
  • Extrinsic typestate. Endpoints tag objects with attributes (FUZZ_SET_ATTR_*), for example "this document is freed", and bail out (FUZZ_BAIL()) instead of misusing them. This stops the fuzzer from reporting bugs that are only API misuse.

The LLM runs only while building the harness (gen, infer) and, optionally, to explain crashes (bugs analyze). The fuzzing loop itself is plain LibAFL with no model in it.

flowchart TD
  A["stitch init #lt;git url#gt;
pin commit, create project"] --> B B["stitch gen (LLM agent)
explore repo, write config/Dockerfile + info.json,
build & test until headers compile"] --> C C["stitch infer (LLM pipeline)
scan-objects → scan-funcs → synth-functions →
classify-data → build-generators"] --> D D[("harnesses/harn1/harness.json
objects · endpoints · generators")] --> E E["stitchi inference to-schema
endpoint snippets → typed C++ shims"] --> F F["stitchi build full fuzzer
shims + library compiled by stitch_libafl_cc
(SanitizerCoverage + ASan)"] --> G G["LibAFL loop (no LLM)
InProcessForkExecutor · call-graph mutators ·
typestate bail-outs · edge-coverage feedback"] --> H H{"crash?"} -->|yes| I["out/crashes/graph_*"] H -->|new edges| J["out/queue/"] J --> G I --> K["stitch bugs exec / analyze
replay · (optional) LLM triage"]

Our experimental setup

Three targets, each in two versions: the latest commit and a release with known, public bugs. Both fuzzers were built with the same clang-17 and AddressSanitizer, inside the same Docker base image, and run for one hour on one CPU, twice each (STITCH got a third run on jsoncpp and rlottie).

TargetVersionKnown bugs present (verified by us)libFuzzer harnessSTITCH endpoints

Fairness rules

  • One CPU per campaign (docker --cpus=1), 60 minutes, 2 repetitions per configuration, no seed corpus for either fuzzer. libFuzzer gets the project's dictionary where one exists.
  • libFuzzer runs in -fork=1 -ignore_crashes=1 -ignore_ooms=1 -ignore_timeouts=1 mode so a crash does not end its hour, matching STITCH, which keeps fuzzing after each crash.
  • Coverage is measured the same way for both: replay each fuzzer's saved corpus through a clang source-coverage build and count covered library lines with llvm-cov. The fuzzers' own edge counters use different instrumentation and are not comparable with each other.
  • A crash only counts if it reproduces when replayed alone under ASan. Up to 300 crash files per run are sampled with a fixed seed, replayed once, and confirmed with two more replays.
  • libxml2 ships four libFuzzer harnesses (api, xml, reader, schema); each got its own CPU-hour. STITCH gets one CPU-hour for the whole library. Where this matters we show both libFuzzer's best single harness and the union of all four.

The host is an Apple Silicon Mac, so every x86-64 container ran under emulation. Absolute speeds are therefore lower than on native Linux for both fuzzers; the comparison between them is unaffected because both ran the same way.

Reproducing the technique

1. Install STITCH

STITCH is a Python CLI that drives Docker. We needed three small local patches, listed here so the run can be reproduced:

mkdir -p ~/Documents/workdir/stitch
cd ~/Documents/workdir/stitch
git clone https://github.com/hgarrereyn/STITCH
git -C STITCH checkout 4b31cde
python3.12 -m venv venv
./venv/bin/pip install ./STITCH/stitch

# 1) Pin the Rust lockfile so the toolchain build does not pull a newer uuid.
perl -pi -e 's#cargo install --path \. --root#cargo install --locked --path . --root#' \
  STITCH/stitch/stitch/docker/stitch.Dockerfile

# 2) Pass OPENAI_BASE_URL into containers for OpenRouter.
perl -pi -e 's/"OPENAI_API_KEY",/"OPENAI_API_KEY", "OPENAI_BASE_URL",/g; s/env = \["OPENAI_API_KEY"\]/env = ["OPENAI_API_KEY", "OPENAI_BASE_URL"]/g' \
  STITCH/stitch/stitch/commands/{infer,bugs,fuzz,dev}.py

# 3) Allow STITCH_DOCKER_EXTRA, for example --cpus=1.
perl -pi -e 's#^(        full_cmd = \["docker", "run", "--rm", "--platform", "linux/amd64"\]\n)#$1        full_cmd += os.environ.get("STITCH_DOCKER_EXTRA", "").split()\n#' \
  STITCH/stitch/stitch/_project.py

export OPENAI_API_KEY="$OPENROUTER_API_KEY"
export OPENAI_BASE_URL="https://openrouter.ai/api/v1"

Choosing and changing the LLM. This STITCH checkout has a built-in default of gpt-5. The screenshots below select OpenRouter's openai/gpt-5 name explicitly with -m. Use stitch init -m <model> to save a project default in stitch.json, or pass -m <model> to gen, infer, or full-mode fuzz to override it for one command. For an existing project, either change the model value in stitch.json or keep using command-line overrides; the precedence is command line, project configuration, then built-in default. Replace openai/gpt-5 with any model identifier supported by your OpenRouter account. Raw fuzzing with --no-triage does not call the model.

2. Create a project and let the build agent configure it

stitch init pins a commit. stitch gen starts an LLM agent that lists the repository, reads headers and CMakeLists.txt, writes a Dockerfile that builds the library with STITCH's compiler wrappers, and keeps fixing it until a test program and a codegen check pass. In the run below it failed on its first build and fixed itself on the next cycle.

cd ~/Documents/workdir/stitch
./venv/bin/stitch init https://github.com/Samsung/rlottie \
  -c ea06d2f29ba01b8d06c00a838d107f5e484ae59b \
  -m openai/gpt-5 samsung_rlottie
cd samsung_rlottie
../venv/bin/stitch gen -m openai/gpt-5
Terminal: stitch init pins rlottie commit ea06d2f and creates the project
Terminal: stitch gen agent inspects the repo, fails a Dockerfile test, troubleshoots, then passes all configuration tests in 89 seconds
STITCH prints Cost $0.0000 because it has no price table for the OpenRouter model name; real costs are in the LLM section below, measured from OpenRouter's usage counter.

3. Let the LLM write the harness specification

stitch infer runs a staged pipeline: find the object types in the headers, find the functions, write an endpoint for each function, fill in missing constructors, classify data types, and build generators for structured inputs (here a "Lottie JSON" generator).

# Run from samsung_rlottie. The harness and all generated files stay in this project.
../venv/bin/stitch infer -m openai/gpt-5 --name harn1 --threads 4
Terminal: stitch infer stages for rlottie v0.2: 30 objects, 37 functions, 37 endpoints, 3 generators in 489 seconds

One endpoint from that spec. The LLM decided how to build a valid animation, which parts of the call to fuzz, and when to bail out:

harness.json entry for rlottie::Animation::loadFromData with FUZZ_PARAM_STR and FUZZ_BAIL

At build time STITCH turns each endpoint into a C++ shim. The shim decodes its parameters from the fuzzer's byte context and runs the snippet:

Generated fuzzer.cpp: exec_shim_11 copies fuzzed parameters out of the context buffer before the endpoint template code

4. STITCH end to end on jsoncpp 1.9.6: harness, build, fuzz, crash

Steps 1–3 used rlottie as the example. For the rest of the walkthrough we switch to jsoncpp 1.9.6, because it carries a known use-after-free (jsoncpp #1623) that STITCH finds within a minute. Every screenshot from here on is a run made for this post with blog/run_demos.sh, which writes each command and its full output to logs/demo/.

cd ~/Documents/workdir/stitch
./venv/bin/stitch init https://github.com/open-source-parsers/jsoncpp \
  -c 1.9.6 -m openai/gpt-5 jsoncpp_1_9_6
cd jsoncpp_1_9_6
../venv/bin/stitch gen -m openai/gpt-5
../venv/bin/stitch infer -m openai/gpt-5 --name harn1 --threads 4

4a. The harness. A STITCH harness is not a single LLVMFuzzerTestOneInput function. It is a spec: one C++ snippet per API function (an endpoint) plus typed inputs and outputs, which the fuzzer chains into call graphs. These are the two endpoints the LLM wrote that, chained together, reach the bug. Reader::parse parses fuzzed text through one of three overloads. getFormattedErrorMessages asks the same reader for its errors and checks an LLM-written property with FUZZ_ASSERT:

# Inspect the two endpoints from jsoncpp_1_9_6.
jq '.endpoints[] | select(.name == "Json::Reader::parse" or .name == "Json::Reader::getFormattedErrorMessages")' \
  harnesses/harn1/harness.json
jq output: the LLM-written C++ snippets for the Json::Reader::parse and Json::Reader::getFormattedErrorMessages endpoints

4b. Build the harness. stitch test checks that the project's Dockerfile builds the library with STITCH's instrumenting compilers (stitch_libafl_cc/cxx), and that code generation works. stitch fuzz then compiles the harness inside its container without printing anything. To show that step, we ran it by hand in the same image: the spec becomes a schema, the schema becomes fuzzer.cpp with one shim per endpoint (123 here), and that is linked with LibAFL and ASan into ./fuzzer. The shim for Reader::parse copies its fuzzed arguments out of the byte context and then runs the LLM's snippet verbatim:

# Validate the generated Dockerfile and code generation from jsoncpp_1_9_6.
../venv/bin/stitch test
stitch test passes build and codegen checks; stitchi build full fuzzer produces fuzzer.cpp with 123 shims and a 20 MB fuzzer; exec_shim_1 source

4c. Fuzz. The same command as the campaigns, limited to five minutes. The animation replays the run's real terminal output at 20× speed, paced by LibAFL's own run-time stamps. Red lines are objectives (crashing graphs):

# Run from jsoncpp_1_9_6. No LLM is used in this raw-fuzzing stage.
STITCH_DOCKER_EXTRA="--cpus=1" ../venv/bin/stitch fuzz \
  --name harn1 --no-triage --hard-rss-limit-mb 2048 \
  -o out/demo_jsoncpp --time-limit-seconds 300
Animated replay of a live five-minute stitch fuzz run on jsoncpp 1.9.6: LibAFL stats lines scroll, objectives rise from 0 to 37
Replay of logs/demo/s3_fuzz.log; every line is from that log (blog/make_fuzz_gif.py). One CPU, 5 min 48 s, 10,910 executions (31 exec/s), 37 objectives, 2,520 of 8,636 edges.
stitch fuzz: 123/123 endpoints enabled, first objective at 17 seconds, 37 objectives after 5 minutes 48 seconds

4d. Replay a crash with ASan. stitch bugs exec replays one graph. The first objective of the live run is not a memory error: it is the LLM's own oracle firing. The FUZZ_ASSERT in getFormatedErrorMessages expects an empty error string after a successful parse, and jsoncpp does not guarantee that. We count these as oracle findings, not bugs. Only 2 of the 37 live objectives reproduced on replay, both this assertion. That low rate is normal for STITCH on this target: in the 1-hour campaigns, 24 of 152 (run 1) and 4 of 253 (run 2) crash files reproduced. The second command replays the use-after-free from the run 2 campaign, which reproduces 3 times out of 3, with symbols and full allocation stacks (scripts/replay_stitch.sh, same build and ASan options as the triage). Reader::parse (shim 1) frees the document buffer. getFormattedErrorMessages (shim 3) then reads the stale error locations that point into it, at json_reader.cpp:761:

# Replace graph_REPLACE_ME with a filename from out/demo_jsoncpp/crashes/.
# ASan is enabled by default; add --no-asan only to compare without it.
../venv/bin/stitch bugs exec -n harn1 \
  -t out/demo_jsoncpp/crashes/graph_REPLACE_ME
stitch bugs exec shows a FUZZ_ASSERT oracle violation; replay_stitch.sh shows AddressSanitizer heap-use-after-free in Json::Reader::getLocationLineAndColumn, freed in Json::Reader::parse

For reference, a frame from an hour-long rlottie 0.2 campaign (the runs behind the findings section):

LibAFL stats during a STITCH run: corpus, objectives, executions, exec/sec around 9.5

5. The libFuzzer baseline on rlottie 0.2: harness, build, fuzz, crash

5a. The harness. Each baseline image starts from STITCH's own base image (same clang-17), checks out the same commit, and builds the project's own fuzz harnesses. rlottie has no in-tree harness, so we used the public render_fuzz.cpp from ISP RAS's oss-sydr-fuzz, which loads fuzzed JSON and renders every frame:

render_fuzz.cpp: LLVMFuzzerTestOneInput loads the input with rlottie::Animation::loadFromData and renders every frame into a 200x200 surface

5b. Build the harness. lf/build_lf.sh builds every baseline twice: with ASan for fuzzing and with source coverage for measurement. This is the recipe:

build_lf.sh: ASan and coverage builds of the jsoncpp, libxml2 and rlottie libFuzzer harnesses

Here is the ASan variant run from a clean checkout: the library with -fsanitize=address,fuzzer-no-link, then the harness linked with -fsanitize=address,fuzzer:

docker run: cmake configure and build of rlottie 0.2 with ASan and fuzzer-no-link, compile and link render_fuzz.cpp into rlottie_render

5c. Fuzz. Without -ignore_crashes, libFuzzer stops at the first crash. From an empty corpus it got there after 356,104 executions, about two seconds at roughly 178,000 executions per second on one CPU. The crash is one of rlottie 0.2's real bugs: the JSON parser hands a NULL string to std::string in parseComposition, which throws an uncaught std::logic_error:

libFuzzer run on rlottie 0.2 from an empty corpus: deadly signal after 356104 executions, std::logic_error in LottieParserImpl::parseComposition, crash file written

The campaigns themselves run in fork mode and keep going past crashes, saving every one (1,494 crash files in one hour):

libFuzzer fork-mode run on rlottie v0.2: 67 million executions in an hour, 1494 crashes ignored and saved

5d. Replay a crash with ASan. Running the harness on one saved crash file gives the ASan report. This crash is the largest SEGV bucket from that campaign (181 files): LottieParserImpl::toColor calls strlen on a NULL color string at lottieparser.cpp:904. The stack stops at frame 2 because glibc's AVX2 strlen has no frame pointer, but frame 2 is already the bug site:

AddressSanitizer SEGV on unknown address 0x0 in strlen called from LottieParserImpl::toColor at lottieparser.cpp:904

What we found

Speed: executions per second

libFuzzer calls one function on a byte buffer inside a persistent process. STITCH forks a child for every test case, decodes a call graph, and runs several API calls through generated shims. The gap is two to three orders of magnitude.

Coverage: library lines reached

Same measurement for both fuzzers: each saved corpus replayed through one source-coverage build, counting only the library's own source files.

How coverage grows during the hour

Each line is a fuzzer's own coverage counter as a share of where that run ended, averaged over repetitions. It shows how quickly each fuzzer saturates, not which reaches more code.

Mutation yield

New corpus entries per 1,000 executions: how often a mutation produced something the fuzzer considered new. STITCH mutates call graphs (insert, delete, splice calls, re-wire objects, change parameters), so a single test case explores more structure. libFuzzer mutates bytes, cheaply and blindly, and makes up for it with volume.

Crashes: from raw objectives to real bugs

TargetFuzzerCrash filesReplayedReproduceDistinct stacks

Every reproducing crash was then grouped by crash site and, for use-after-free, by where the memory was freed, and each group was labelled with the rules in scripts/label_buckets.py: real (the defect is in the library and the call respects the API contract), harness (the harness broke the contract: freed an object it still used, passed NULL where the API forbids it, passed the wrong object as a context, called an internal parser callback outside a parse), oracle (an LLM-written FUZZ_ASSERT that fails on correct behaviour) and review (inconclusive; not counted as real).

TargetFuzzerRealHarnessOracleReviewReal bugs (distinct)

What the LLM buys, and what it costs

SpecSourceObjectsFunctionsEndpointsGeneratorsInfer timeLLM cost

The libFuzzer harnesses reach a handful of entry points: jsoncpp's harness only uses CharReader::parse, rlottie's loads JSON and renders, and libxml2's four harnesses cover the parser, reader, schema validator and a hand-written API driver. A STITCH spec makes every public function an endpoint: 144 for jsoncpp, about 1,300 to 1,500 for libxml2. That is where its advantage comes from: code that no hand-written harness calls, such as jsoncpp's legacy Json::Reader or libxml2's Schematron validator.

Why STITCH behaves differently

Caveats

    Conclusion

    Our investigation shows that LLM-generated API specifications can expand what fuzzing reaches, but they do not make conventional fuzzers obsolete. The clearest success was jsoncpp: generated endpoints exercised the legacy Json::Reader API and exposed its known use-after-free, while the existing libFuzzer harness only targeted CharReader. That is the real research opportunity—not replacing coverage-guided fuzzing, but automating the construction of richer, stateful harnesses for APIs that are difficult to cover by hand.

    The same experiments also define the limits. libFuzzer executed two to three orders of magnitude more test cases, and broader API coverage only helps when the generated specification preserves meaningful fuzz input. One rlottie specification replaced fuzzed files with fixed JSON, cutting off the parser entirely; elsewhere, generated lifetime errors and incorrect assertions produced crashes that were not library bugs. These are not details that raw crash counts can reveal.

    Our practical verdict is to use this technique as a complement to conventional fuzzing: keep fast, focused harnesses where they work, add LLM-generated call-sequence harnesses where API reach is the bottleneck, and budget for human review of the specification plus independent replay of every candidate finding. The LLM can automate harness construction; it cannot automate away validation.

    Credits

    The paper STITCH: Automatic, Expressive, and Scalable Fuzzing with Stitching and the STITCH tool were created by:

    • Harrison Green, Carnegie Mellon University
    • Fraser Brown, Carnegie Mellon University
    • Claire Le Goues, Carnegie Mellon University

    Part 2: STITCH on a library without source code

    The follow-up post takes STITCH to Samsung's closed-source image codec libimagecodec.quram.so: decompiling the AArch64 binary, rebuilding it as C that matches the phone's library bit for bit on 4,059 of 4,059 outputs, building ground truth on a Galaxy S25, and fuzzing the rebuild. Coming soon.

    Reproduce it

    All scripts used here: campaign runner (scripts/job.sh), crash replay (scripts/triage*.sh), coverage (scripts/cov*.sh), metrics (scripts/metrics.py), the libFuzzer builds (lf/build_lf.sh) and the spec pruner (scripts/prune_spec.py).

    Raw run table
    ConfigFuzzerRepExecsExec/sCorpusCrash filesLib lines