What Is Fuzzing and Why Coverage Guidance Works
Fuzzing feeds a program mutated inputs and watches for crashes. Coverage feedback keeps inputs that reach new code, so an impossible search becomes short.

Fuzzing is automated testing with inputs a person would never write. A program called a fuzzer generates input, runs your code on it, and checks whether the code crashed, hung or tripped a safety check. It repeats that millions of times. Most of what it generates is garbage, and that is the point: real attackers send garbage, and parsers that were only ever tested on well-formed files tend to fail on it. This post explains what a fuzzer does, why the older random approach almost never finds deep bugs, and why feedback from the program itself, called coverage guidance, fixes that. No prior fuzzing experience is assumed, and the example is small enough to follow by hand.
The practical follow-up is the guide to fuzzing C and C++ code, which builds a working harness. Here the goal is the idea behind it, so the tools make sense when you use them.
What a fuzzer actually does
A fuzzer needs three things: a target, an input generator and a way to notice failure.
The target is a function or program that takes bytes. A PNG decoder, a JSON parser and a DNS message reader are all targets.
The input generator produces candidate inputs. The oldest design is pure random: fill a buffer with random bytes and run the target. A better one is mutation: start from a valid sample and make small changes, such as flipping a bit, overwriting a byte with an extreme value like 0 or 255, deleting a chunk, or copying a chunk to another place. Valid inputs mutated slightly stay close enough to valid to get past the first checks of a parser.
The failure detector is whatever turns a bug into a visible event. A segmentation fault is the obvious one. Many bugs are silent, though: reading one byte past a buffer usually returns a value and the program carries on. Compiling the target with a sanitizer, such as AddressSanitizer, makes the program stop at the first bad memory access, so those bugs become failures. A fuzzer without a sanitizer finds only the bugs that happen to crash.
When a failure occurs, the fuzzer saves the exact input that caused it. That file reproduces the bug every time, which is what makes fuzzing findings easy to act on.
Why blind random input rarely works
Consider a target with a check that needs four specific bytes in a row.
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
int check(const uint8_t *d, size_t n)
{
if (n < 4)
return 0;
if (d[0] == 'F')
if (d[1] == 'U')
if (d[2] == 'Z')
if (d[3] == 'Z')
abort(); /* the bug */
return 0;
}A blind generator must produce all four bytes in one attempt. Each byte has 256 possible values, so the chance that one random input starts with FUZZ is one in 256 to the fourth power. A few lines of Python give the exact number:
p = 256 ** 4
print("one blind attempt succeeds with probability 1 in", p)one blind attempt succeeds with probability 1 in 4294967296That is over four billion attempts on average. Real formats are worse. A PNG file starts with an eight-byte signature, and a decoder rejects anything that does not match before it reads a single other byte. Random input would spend its whole life being rejected at the front door, never touching the code behind it, where the bugs are.
What coverage guidance changes
A coverage-guided fuzzer watches which parts of the target ran. The compiler inserts a small counter update at each branch, so after every run the fuzzer can read a record of the paths taken. That record is called coverage. Clang provides it with -fsanitize=fuzzer or -fsanitize-coverage=trace-pc-guard, and AFL++ provides it through its compiler wrappers.
The rule that follows is simple: if an input makes the program run code that no earlier input reached, keep it. Add it to the corpus, the fuzzer's collection of interesting inputs, and mutate it in later rounds.
Trace the FUZZ target through that rule. The first input to get d[0] == 'F' right executes one more branch than any input before it, so it is kept. The fuzzer then mutates that input. It does not need to guess the first byte again, because it starts from an input that already has it. The next milestone, d[1] == 'U', needs only a one in 256 chance on one byte, and when it hits, the new input is kept too. Each stage is an independent small search.
The cost changes from multiplying the chances to adding them. Each byte takes about 256 attempts on average, because each stage succeeds with probability 1 in 256:
per_byte = 256
stages = 4
print("blind: ", 256 ** stages, "attempts on average")
print("guided: ", per_byte * stages, "attempts on average")blind: 4294967296 attempts on average
guided: 1024 attempts on averageThat is the whole idea. The figures are expected values from the arithmetic above, not a measurement of any particular fuzzer, and real fuzzers add smarter mutations, so they find this one faster still. The gap between four billion and about a thousand is why coverage guidance turned fuzzing from a curiosity into a standard security practice. The AFL project, which popularized the technique, describes the same mechanism in its documentation.
The loop in plain steps
Every coverage-guided fuzzer runs a version of this loop:
Start with a corpus of seed inputs, possibly just one empty file.
Pick an input from the corpus.
Mutate it to produce a new candidate.
Run the target on the candidate and record the coverage.
If the coverage includes something new, add the candidate to the corpus.
If the target crashed, hung or failed a sanitizer check, save the candidate as a finding.
Go to step 2.
Details differ between tools. Some fuzzers prefer inputs that found rare paths, a policy libFuzzer calls the power schedule. Some track edges (a jump from one block to another), which distinguishes A then B from B then A, where plain block coverage would not. But the loop above is the core of libFuzzer, AFL++ and honggfuzz alike.
What counts as "new" coverage
Coverage is recorded as a set of edges, with hit counts bucketed so that running a loop 3 times and running it 4 times can be told apart from running it 200 times. A new input is interesting if it covers a new edge or moves an existing edge into a new bucket. This is why corpora fill with inputs that look nearly identical to a human: each one differs in one branch outcome or one loop count.
It also explains the common failure of coverage guidance. If a gate in the code depends on something that is not a branch, such as a checksum computed over the whole input, then changing any byte invalidates the checksum, and no mutation produces visible progress. The fuzzer cannot tell that it was close. Fuzzing practice has three standard remedies: write a dictionary of known tokens, supply seeds that already pass the gate, or use a custom mutator that recomputes the checksum after each change. Those are covered in the follow-up posts.
A worked trace
Here is what a guided fuzzer's corpus might look like after the first few hundred runs on the FUZZ target. The inputs are shown as ASCII for readability; a real fuzzer stores raw bytes.
seed: "" edges: 1 (n < 4 branch)
kept #1: "\x00\x00\x00\x00" edges: 2 (passed the length check)
kept #2: "F\x00\x00\x00" edges: 3 (d[0] == 'F')
kept #3: "FU\x00\x00" edges: 4 (d[1] == 'U')
kept #4: "FUZ\x00" edges: 5 (d[2] == 'Z')
crash: "FUZZ" abort() reachedThe listing is illustrative: a real run would keep other inputs along the way and would reach FUZZ through a different sequence. What matters is the staircase. Each kept input is one step above the previous one, and the fuzzer climbs by mutating the last step, not by starting over.
Why this finds real bugs
Real parsers are staircases too. A format has a signature, then a header, then a table of lengths, then records, then nested structures. Each level checks the level before it. A bug in the record handler can only be reached by an input that passes the signature, the header and the table. A person writing a test case has to construct such an input by hand, using knowledge of the format. A coverage-guided fuzzer builds it incrementally, by keeping every partial success.
That is also why the seed corpus helps so much: a real sample file is already at the top of the staircase, and mutation starts from there instead of climbing all the way up.
The bugs found this way are not exotic. They are the ordinary mistakes of C and C++ programs written under time pressure: a length read from the file and trusted, an index not compared with the array size, an integer that overflows before it is used as a size, a pointer used after the memory behind it was released. Fuzzing finds them because it tries the inputs where the checks are missing.
What fuzzing cannot do
Be clear about the limits so the technique is used where it pays.
It finds bugs the program reports. A wrong answer that does not crash is invisible. If you can write a check, such as "decoding what we just encoded gives the same bytes back", put it in the fuzz target, so a violation becomes a failure.
It explores the code it can reach. Branches that require a cryptographic signature or a complex handshake may stay unexplored without help. The coverage report from a long run tells you what was missed.
It does not prove absence of bugs. A fuzzer that runs for a week and finds nothing has covered what it covered, nothing more.
It is not a substitute for tests or review. It covers inputs nobody planned for. Tests cover behavior somebody intended.
When to start
Fuzz when your code parses data from outside the program: files, network packets, command-line arguments in untrusted scripts, messages from another process. It pays most in C and C++, where a parsing mistake becomes memory corruption, and it still finds panics, hangs and logic errors in memory-safe languages such as Rust and Go, which have their own native fuzzing support. Skip it for code that only handles trusted, validated data, or where the input space is tiny enough to test exhaustively.


