Definition
A seed corpus is the set of example inputs that a fuzzer starts from. A fuzzer is a tool that runs a program on very many automatically made inputs to find inputs that make it fail; it makes new inputs by changing the seeds. A coverage-guided fuzzer adds each new input that executes code no earlier input executed, so the seeds are the first members of a growing corpus. A seed corpus is not a random seed, the number that starts a fuzzer’s random number generator.
The idea
An image decoder rejects any input that lacks the format’s signature bytes or that has a section with a wrong checksum §4.32. Random bytes almost never pass both tests, so a fuzzer that starts from nothing spends most of its runs in the code that rejects input. One real image file used as a seed passes every test on its first run, and most small changes to it land inside the decoder. Seeds let the fuzzer start deep in the program instead of at its entrance.
The starting points of a search party are a fair picture. The party fans out from each starting point, and points spread across the area cover more ground than points crowded into one corner. The picture stops in one respect: a coverage-guided fuzzer also fans out from new places it finds, so an area with no starting point can still be reached, only more slowly, or not within the time available.
How it works
List the input classes, the kinds of input the program treats differently. Dividing all inputs into classes that the program should handle alike is equivalence partitioning §10.32. Include the smallest valid input, a typical one, and each version, message type and option. Add the cases of boundary-value testing §10.31: each limit, one below it and one above it, and the empty input. Add malformed inputs: a truncated input, a length field that disagrees with the real length, a wrong checksum, an unknown type or version. For a protocol with state, add short message sequences that reach each state.
Collect examples from unit tests §10.1 and conformance tests, the format’s specification, inputs that once made the program fail (kept as regression tests §10.4), small samples from real use, and hand-written cases.
Make each malformed seed wrong in exactly one way, so that it reaches the test for that defect.
Keep seeds small. Short inputs run faster, and a random change to a short input more often touches a byte that matters.
Use the harness’s input format. The fuzz harness §10.13, the code between the fuzzer and the program, may read some bytes as instructions to itself, such as which function to call; each seed must contain those bytes.
Label and store: name each seed after its class, and keep the set under version control.
Run each seed once before fuzzing §10.9: confirm that none already makes the program fail, and see which code the seeds cover.
Worked example
A toy format: byte 0 is a type, and only type 01 is defined; byte 1 is a payload length , at most 4; then come payload bytes; the last byte is a checksum, the sum of all earlier bytes modulo 256 (the remainder after division by 256). Bytes are written in hexadecimal; the payload bytes 41 to 45 are the letters A to E, with decimal values 65 to 69. Eight seeds cover eight classes:
Empty input: no bytes. It reaches the test for a too-short input.
Minimal valid:
01 00 01. The checksum is .Typical valid:
01 03 41 42 43 CA. The sum is , which isCAin hexadecimal.Exact limit:
01 04 41 42 43 44 0F. The sum is , and , which is0F.One over the limit:
01 05 41 42 43 44 45 55. The sum is , and , which is55. The checksum is right, so only the length is wrong.Truncated:
01 04 41 42. The length says 4 payload bytes, but only 2 follow, and the checksum is missing.Wrong checksum:
01 00 02, the minimal message with its checksum 1 too high.Unknown type:
07 00 07. The checksum is right, but type07is not defined.
Each malformed seed is wrong in exactly one way. A seed with both a bad length and a bad checksum would be rejected by whichever test the parser runs first, and the other test would never see it. Compare 100 copies of the valid message 01 02 41 42 86, whose sum is , which is 86. All 100 copies take the same path through the parser, so together they cover exactly what one of them covers, and none reaches a rejection test. The eight seeds reach the acceptance path and every rejection test of this format: an input shorter than the 2-byte header, an unknown type, a length above 4, a message shorter than its length field says, and a wrong checksum.
Stated precisely
No formula measures the quality of a seed corpus. What can be stated exactly is whether it represents a chosen list of classes. Let be the set of input classes chosen for the program, and let be the set of classes to which seed belongs; one seed can belong to several classes. A seed corpus represents when The statement is only as good as . The eight seeds above represent their eight classes, but not, for example, a valid payload that contains the byte 00, which matters if the parser treats zero bytes specially.
At start-up the fuzzer runs every seed once, and its covered set, the coverage facts observed so far, begins as the union of the facts the seeds produce. libFuzzer §10.26 marks this point in its output as INITED. The seeds promise nothing about inputs far from all of them.
Limits and common mistakes
More seeds are not better seeds. Near-duplicates add no coverage but run at every start. Large seeds slow every run, and a one-byte change to a 1 MiB file rarely hits the byte that matters.
A seed in the wrong format tests the wrong thing. If the harness reads the first byte as a choice of function, a raw message file used as a seed has its first byte read as that choice.
Seeds from real use can contain passwords, keys or personal data, which then spread as test data. Remove the secrets or use synthetic examples.
A seed that already makes the program fail is a bug report, not a starting point, and fuzzers report it at start-up. Fix the bug, or keep the seed with the known failures.
Corpus minimization §10.15 keeps only inputs that add coverage, so it can drop a seed whose class shares its code path with another seed. In a parser whose only length test is , the exact-limit message takes the same edges as the typical one. Keep the labeled seed set apart from the fuzzer’s working corpus, and never minimize the labeled set.
A run is repeatable only if both the seed corpus and the random seed are recorded. libFuzzer’s option -seed=N sets the random seed; its default, 0, makes libFuzzer generate a new one.
Seeds steer the search. Deciding what counts as a failure stays the job of the test oracle §10.5.
Questions answered
Which valid, malformed, minimal, and boundary examples are represented?
A seed corpus, the set of example inputs a fuzzer starts from, should represent at least the following examples, and checking a corpus means listing which of them are present and which are missing.
Valid: a typical accepted input, and one for each version, message type and option.
Malformed: a truncated input, a length field that disagrees with the real length, a wrong checksum, an unknown type and an unknown version, each wrong in exactly one way so that it reaches the test for that defect.
Minimal: the empty input, a single byte, and the smallest accepted input.
Boundary: for each limit, an input exactly at the limit, one just below it and one just above it, such as payload lengths 3, 4 and 5 when 4 is the maximum.
State: for a protocol with state, short message sequences that reach each state.
To answer the question for a given corpus, label each seed with the classes it belongs to, list every class of the input format that has no seed, and report those missing classes. The number of seed files says nothing on its own: 100 copies of one valid message represent one class.
Related entries: Corpus minimization (§10.15), Boundary-value testing (§10.31), Generation-based fuzzing (§10.11), Deterministic replay (§10.37), Equivalence partitioning (§10.32), Coverage-guided fuzzing (§10.12), Input dictionary (§10.16). Further reading: [24].