Skip to content

Fuzz Testing

In one line

Fuzz testing bombards your code with random/malformed inputs — finds crashes and security issues that normal tests miss.

In simple words

Fuzz testing (fuzzing) automatically generates random, malformed, or unexpected inputs and feeds them to your program to see if it crashes. It's excellent at finding edge cases and security vulnerabilities.

Types of fuzzing:

  1. Black-box fuzzing — generates random inputs without knowing the code
  2. White-box fuzzing — uses code structure to generate targeted inputs
  3. Grammar-based fuzzing — generates inputs following a structure (e.g., valid-ish JSON)
  4. Mutation-based fuzzing — takes valid inputs and mutates them (flip bits, truncate)

What fuzzing finds:

  • Buffer overflows / out-of-bounds access
  • Null pointer dereferences
  • Integer overflows
  • Unhandled exceptions / crashes
  • Security vulnerabilities (injection, XSS)
  • Memory leaks
  • Assertion failures

Modern fuzzers use coverage-guided feedback: they track which inputs reach new code paths and mutate those inputs to explore more paths. This is very effective at finding deep bugs.

Tools: libFuzzer (C/C++), AFL, OSS-Fuzz, jsfuzz (JS), hypothesis (Python).

Example

javascript
// Fuzz testing a JSON parser with jsfuzz
import { FuzzedDataProvider } from 'jsfuzz';

function fuzzParser(data) {
  const provider = new FuzzedDataProvider(data);
  const input = provider.consumeString(100);

  try {
    const parsed = JSON.parse(input);
    // Round-trip: parse then stringify should not throw
    JSON.stringify(parsed);
  } catch (e) {
    if (e instanceof SyntaxError) return; // expected for invalid JSON
    throw e; // unexpected error — fuzzing found a bug!
  }
}

// The fuzzer generates thousands of random inputs
// and calls fuzzParser with each one.
// If fuzzParser throws, a bug was found.

// Coverage-guided fuzzing with libFuzzer (C/C++):
// int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
//   parse_json(data, size);  // if this crashes, bug found!
//   return 0;
// }
// Run: ./fuzzer -max_len=100 -max_total_time=60

The fuzzer generates random inputs and calls your function. If it crashes or throws unexpectedly, a bug was found. Coverage-guided fuzzers are especially effective — they explore new code paths systematically.

Common confusions

  • Confused with: property-based testing

    The difference: Fuzz testing feeds random inputs to find crashes — it checks for crashes/exceptions, not correctness. Property-based testing checks that specific properties/invariants hold for random inputs — it has assertions about correctness. Fuzzing is 'does it crash?'; property-based is 'is it correct?'. Fuzzing finds crashes; PBT finds logic errors.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary