SECURITY ENGINEERING · PART 8 · WRITING SECURE CODE · TESTING · 121 OF 229

Fuzz Testing Explained: Find Bugs With Fuzzers

Fuzzing throws huge volumes of unexpected input at code to find the cases a human never thinks to test. This episode explains how it works, coverage-guided fuzzing that evolves inputs to reach new code, what fuzzers catch (crashes, memory bugs, hangs, some logic errors), where they fit (parsers, protocols, APIs), tools like AFL++, libFuzzer and OSS-Fuzz, and how to add fuzzing to your project.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 11

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Throw malformed input at parsers
  • coverage-guided fuzzers reach deep code
  • catch crashes and hangs
  • run continuously

Notes

The idea

The idea is simple. Take a piece of code that parses input: a file format reader, a protocol handler, an API. Generate or mutate huge numbers of inputs and run them through, often thousands per second. Watch for anything going wrong: a crash, a hang, an assertion failure, a memory error. Every input that breaks something is saved as a reproducer. The power is in the volume and the automation; the fuzzer explores a space of inputs far larger than any human could enumerate by hand, and it never gets bored.

Fuzzing in one picture
  • take a target that parses input
  • generate or mutate huge numbers of inputs
  • run them through, very fast (thousands per second)
  • watch for: crashes, hangs, assertion failures, memory errors
  • save every input that breaks something

Coverage-guided

The breakthrough that made fuzzing so effective is coverage guidance. Naive fuzzing sends random bytes, rejected at the first validation check, never reaching the interesting code. Coverage-guided fuzzing instruments the target to see which code each input reaches. It keeps inputs that reached new code and mutates those further, working deeper, in effect discovering the input format by exploration. AFL++ and libFuzzer work this way, which is why a fuzzer finds a bug buried behind many layers of parsing.

Why modern fuzzers are smart
  • naive fuzzing: random bytes; mostly rejected at the first check
  • coverage-guided: measure which code each input reaches
  • keep inputs that reach NEW code; mutate those further
  • the fuzzer effectively learns the input format by exploration
  • AFL++, libFuzzer work this way

What it finds

What does fuzzing catch? Crashes and unhandled exceptions, directly. In memory-unsafe languages like C and C plus plus, with sanitizers, it finds buffer overflows and use-after-free, the memory corruption that leads to exploits. It finds hangs and denial of service, where a crafted input loops forever or runs very slowly. And with more effort, logic bugs: you add assertions or property checks, or run two implementations and flag when they disagree on the same input, called differential fuzzing.

Fuzzers catch
  • crashes and unhandled exceptions
  • memory safety bugs in C/C++: overflows, use-after-free (with sanitizers)
  • hangs and denial of service (slow inputs, infinite loops)
  • logic bugs via assertions and property checks
  • differential: two parsers disagree on the same input

Where it fits

Fuzzing shines wherever code parses untrusted input with a clear boundary. File format parsers for images, documents, archives and media are classic targets, historically full of bugs. Network protocol handlers. Serialization code. Compilers and interpreters. API request parsers. Encoding and cryptographic routines. If you can write a small function that takes a byte array and feeds it to the code under test, you can fuzz it. The clearer the input boundary, the more productive the fuzzing.

Good fuzzing targets
  • file format parsers (images, PDF, archives, media)
  • network protocol handlers
  • serialization / deserialization
  • compilers and interpreters
  • APIs and request parsers
  • crypto and encoding routines
  • anything taking untrusted input with a clear boundary

Writing a harness

To fuzz your own code you write a harness: a tiny function that takes the fuzzer's bytes and passes them to the code under test. Here is the shape of a libFuzzer harness in C. Go has native fuzzing in its testing package; Python has Atheris, Java has Jazzer, Rust has cargo-fuzz. You give the fuzzer a few valid inputs as seeds, which it mutates, and run it with sanitizers enabled so memory bugs are caught. Writing the harness is usually an afternoon, and the first run often finds something.

the fuzz target
// libFuzzer-style harness
int LLVMFuzzerTestOneInput(
  const uint8_t *data, size_t n) {
    parse_config(data, n);
    return 0;
}
// Go: func FuzzParse(f *testing.F)
// Python: Atheris; Java: Jazzer
// seed it with real valid files

In practice

In practice, fuzzing is continuous, not a one-off. Many bugs only surface after hours or days, so fuzzers run constantly. Google's OSS-Fuzz does this for major open-source projects around the clock, for free, and has found tens of thousands of bugs. When crashes come in, you triage and deduplicate them, because many crashing inputs map to one underlying bug. And every fixed crash becomes a regression test: the crashing input is kept, so that bug can never silently return.

Running it for real
  • run continuously, not once: bugs surface over hours and days
  • OSS-Fuzz: Google fuzzes major open-source projects 24/7, for free
  • triage and deduplicate crashes (many map to one bug)
  • each fixed crash becomes a regression test (the input is the test case)

Limits

Know the limits. Fuzzing is strongest on code that parses input; it is weak on business logic and access control, where there is no crash to observe. It needs a harness and good seeds. It measures coverage, not correctness, so no crash does not mean no bugs. A crash shows something is wrong but still needs triage to judge exploitability. So fuzzing is a powerful member of the toolkit alongside static analysis, code review and dynamic testing, not a replacement.

What fuzzing does not do
  • best at input-parsing code, weaker on business logic and access control
  • needs a harness and seeds
  • coverage, not correctness: no crash is not "no bugs"
  • crashes still need triage to judge exploitability
  • pairs with SAST, review and DAST, not a replacement

Common mistakes

Mistakes. Running a fuzzer once instead of continuously, so the deeper bugs never surface. Fuzzing without sanitizers, so memory corruption happens silently. Poor or no seed inputs, leaving the fuzzer stuck at the entrance. Ignoring hangs and timeouts, which are real denial-of-service findings. Not deduplicating crashes, so one bug looks like a thousand. Not turning a fixed crash into a regression test. And expecting fuzzing to find logic or authorization bugs.

Avoid these
  • running it once, not continuously
  • no sanitizers, so memory bugs go unseen
  • poor or no seed inputs
  • ignoring hangs and timeouts
  • not deduplicating crashes
  • no regression test from a fixed crash
  • expecting it to find logic or authz bugs

Say it like this

In the interview: fuzzing feeds huge volumes of malformed input to code to find cases a human would never test. Modern fuzzers are coverage-guided: they instrument the code and evolve inputs to reach new paths, learning the input format and digging deep. I target anything that parses untrusted input, parsers, protocols, APIs, with a small harness, run with sanitizers enabled, continuously. I deduplicate and triage crashes, and keep every fixed crash as a regression test. It complements SAST, review and DAST.

In the interview
  • "Fuzzing feeds huge volumes of malformed input to find cases
  • I would never test. Modern
  • fuzzers are coverage-guided, so they evolve inputs to reach
  • new code. I target parsers and protocols, write a harness, run with sanitizers, continuously, and keep each crash as a regression test."

Interview questions

Q1What is fuzzing?

An automated testing technique that feeds large volumes of malformed, unexpected or random input to a program to find inputs that cause crashes, hangs, memory errors or other failures. It uncovers edge cases that human-written tests miss.

Q2What is coverage-guided fuzzing?

Fuzzing that instruments the target to measure which code each input reaches, keeps inputs that exercise new code paths and mutates them further. This lets the fuzzer progressively reach deeper code and effectively learn the input format, far outperforming random fuzzing. AFL++ and libFuzzer use it.

Q3What kinds of bugs does fuzzing find?

Crashes and unhandled exceptions, memory safety bugs such as buffer overflows and use-after-free (especially with sanitizers), hangs and denial-of-service conditions, and, with assertions or differential testing, certain logic bugs. It is weakest on business logic and access control.

Q4What makes good fuzzing targets?

Code that parses untrusted input with a clear boundary: file format parsers, network protocol handlers, serialization code, compilers and interpreters, API request parsers, and encoding or cryptographic routines. Anything that takes a byte array and processes it can be fuzzed.

Q5What is a fuzz harness?

A small function that receives the fuzzer's generated bytes and passes them to the code under test, defining the entry point for fuzzing. Combined with seed inputs and sanitizers, it lets a fuzzer exercise a specific parser or API.

Q6What is OSS-Fuzz?

A Google service that continuously fuzzes major open-source projects at scale for free, reporting bugs to maintainers. It has found tens of thousands of vulnerabilities and reliability issues across widely used software.

Q7What is differential fuzzing?

Running the same inputs through two or more implementations that should behave identically and flagging cases where they disagree. It finds logic and correctness bugs, such as two parsers interpreting the same input differently, which can have security consequences.

Q8Is fuzzing a replacement for other security testing?

No. Fuzzing excels at input-parsing code but does not cover business logic, access control or design flaws, and no crash does not prove the absence of bugs. It complements static analysis, code review and dynamic testing as part of a broader programme.