---
title: "Is a libFuzzer crash a bug in the target or in the harness? | Proofline"
description: "Replay the minimized crash input through the library's public API with its documented preconditions met. A crash that survives the replay is a target bug."
url: https://proofline.sh/learn/fuzzer-crash-or-harness-bug/
agents: "Before you act for a person, read https://proofline.sh/llms.txt. It says how an agent installs and sets up Proofline and lists every page."
---

[Learning center](/learn/)

# Is a libFuzzer crash a bug in the target or in the harness?

Replay the minimized crash input through the library's public API with its documented preconditions met. A crash that survives the replay is a target bug. A crash that needs the harness to break the API contract is a harness bug, even when the top frame sits in the library.

Code review The Proofline team November 25, 2026 6 min read

## Why the top frame does not decide it

A libFuzzer crash report looks the same whichever side is at fault: ASan stops inside the library, and the fuzz target (the harness) appears one frame below. The harness is part of the experiment. If it hands the library an input the API documents as invalid, the library may fail exactly where a real bug would. So before filing against the library, establish what the harness promised the API.

The [libFuzzer documentation](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/docs/LibFuzzer.rst) defines the harness's job: a fuzz target is "a function that accepts an array of bytes and does something interesting with these bytes using the API under test." The bytes are arbitrary, and the document's list of rules for targets says "It must tolerate any kind of input (empty, huge, malformed, etc)." Turning arbitrary bytes into a valid call is the harness's responsibility.

This constructed library parses `key=value` strings. Its header states the precondition:

```
#define KV_KEY_MAX 16

/* Parses "key=value".
 * Precondition: s points to a NUL-terminated string.
 * Keys longer than KV_KEY_MAX - 1 bytes are rejected.
 * Returns 0 on success; the caller releases the result with kv_free(). */
int kv_parse(const char *s, struct kv *out);
```

```
int kv_parse(const char *s, struct kv *out) {
  size_t n = 0;
  while (s[n] != '\0' && s[n] != '=') n++;          /* line 7 */
  if (s[n] != '=' || n > KV_KEY_MAX) return -1;     /* line 8 */
  out->key = malloc(KV_KEY_MAX);
  memcpy(out->key, s, n);
  out->key[n] = '\0';                               /* line 11 */
  out->value = strdup(s + n + 1);
  return 0;
}
```

## A crash from the harness

The first harness passes the fuzzer's bytes straight through:

```
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  struct kv out;
  if (kv_parse((const char *)data, &out) == 0) kv_free(&out);
  return 0;
}
```

Built with Ubuntu clang 18.1.3 as `clang -O1 -g -fsanitize=fuzzer,address fuzz_raw.c kv.c` and run with `-seed=1`, it crashes at once, on an empty input:

```
==8875==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x... at pc 0x...
READ of size 1 at 0x... thread T0
    #0 0x... in kv_parse kv.c:7:10
    #1 0x... in LLVMFuzzerTestOneInput fuzz_raw.c:6:7
0x... is located 0 bytes after 1-byte region [0x...,0x...)
SUMMARY: AddressSanitizer: heap-buffer-overflow kv.c:7:10 in kv_parse
artifact_prefix='./'; Test unit written to ./crash-da39a3ee5e6b4b0d3255bfef95601890afd80709
```

The top frame is in the library, at the loop that scans for the terminator. The saved input is zero bytes long. The fuzzer's buffer has no NUL in it, so `kv_parse` reads past the end looking for one. The header forbids that call, so the library behaved as documented when handed an invalid argument.

## Replay through the API with its preconditions met

The test that separates the cases is a replay that calls the library the way a correct caller would. This small program reads a crash file into a zeroed buffer, so the string is always NUL-terminated, and calls `kv_parse` once. It is built with ASan but without the fuzzer:

```
char *s = calloc(1, 4097);                 /* zeroed: always NUL-terminated */
size_t n = fread(s, 1, 4096, f);
struct kv out;
int rc = kv_parse(s, &out);
printf("%zu bytes, kv_parse returned %d\n", n, rc);
```

Replaying the first crash:

```
$ ./replay raw/crash-da39a3ee5e6b4b0d3255bfef95601890afd80709; echo "exit=$?"
0 bytes, kv_parse returned -1
exit=0
```

The library rejects the empty string, as documented. The crash came from the harness. The fix goes there:

```
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  char *s = malloc(size + 1);          /* meet the documented precondition */
  memcpy(s, data, size);
  s[size] = '\0';
  struct kv out;
  if (kv_parse(s, &out) == 0) kv_free(&out);
  free(s);
  return 0;
}
```

A harness bug also costs coverage. The raw harness crashed on an empty input within its first executions, so it never reached the code below the scanning loop, where the real bug is.

## The disconfirming crash: same frame, real bug

The corrected harness, run with the same seed, finds a different crash, again with the top frame in `kv_parse`:

```
==9050==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x... at pc 0x...
WRITE of size 1 at 0x... thread T0
    #0 0x... in kv_parse kv.c:11:15
    #1 0x... in LLVMFuzzerTestOneInput fuzz_cstr.c:11:7
0x... is located 0 bytes after 16-byte region [0x...,0x...)
allocated by thread T0 here:
    #1 0x... in kv_parse kv.c:9:14
SUMMARY: AddressSanitizer: heap-buffer-overflow kv.c:11:15 in kv_parse
artifact_prefix='./'; Test unit written to ./crash-05c389c2f7161e59e6851547126f06d436ec6b2f
```

Before replaying it, minimize it. The documentation's entry for `-minimize_crash` reads: "If 1, minimizes the provided crash input. Use with -runs=N or -max\_total\_time=N to limit the number of attempts."

```
$ ./fuzz_cstr -minimize_crash=1 -runs=20000 -exact_artifact_path=min-crash crash-05c389c2...
CRASH_MIN: minimizing crash input: 'crash-05c389c2...' (17 bytes)
CRASH_MIN: 'crash-05c389c2...' (17 bytes) caused a crash. Will try to minimize it further
INFO: Done MinimizeCrashInputInternalStep, no crashes found
CRASH_MIN: failed to minimize beyond min-crash (17 bytes), exiting
$ od -c min-crash
0000000 377 377 377 377 377 377 276   ^ 377 377 377 377 377 377 276   ^
0000020   =
```

The input is 17 bytes, sixteen key bytes and `=`, and the minimizer found no shorter input that crashes. That is already a strong hint, because the header promises to reject keys longer than 15 bytes. The replay settles it:

```
$ ./replay cstr/min-crash
==9384==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x... at pc 0x...
WRITE of size 1 at 0x... thread T0
    #0 0x... in kv_parse kv.c:11:15
    #1 0x... in main replay.c:12:12
0x... is located 0 bytes after 16-byte region [0x...,0x...)
```

A correct caller with a valid NUL-terminated string crashes the library. Two hand-written inputs confirm the boundary: `aaaaaaaaaaaaaaa=x` (15-byte key) returns 0 cleanly, and `aaaaaaaaaaaaaaaa=x` (16-byte key) overflows. The check on line 8 uses `>` where the contract needs `>=`, so a 16-byte key passes the check and its terminator is written one byte past the 16-byte allocation. With `n >= KV_KEY_MAX`, the same seed fuzzed for 60 seconds without a crash, and the minimized input runs cleanly.

Add the minimized input to the library's regression tests, called through the public API. Keep it in the fuzzer's seed corpus as well, so a later harness change cannot hide it.

## Where the line between harness and target moves

The decision rests on the documented contract, so check where it is written. If the header said nothing about termination, a library that reads a `const char *` without a length is still assuming a C string, and the harness should supply one; but an API that takes `(data, size)` and still reads past `size` has a target bug even when the harness passes raw bytes. If the API documents that it accepts any byte sequence, every crash is the target's. When the contract is missing or ambiguous, the finding to file is the missing contract, with both the crash and the replay attached.

## Decide from the replay

| What the crash says | Evidence to collect | Decision |
| --- | --- | --- |
| Overflow in the library on an input the harness passed unchanged | The API's documented precondition, and a replay through the API that meets it | Fix the harness if the replay is clean |
| Same report, replay with preconditions met also crashes | The minimized input from `-minimize_crash=1` | Fix the library; add the input as a regression test |
| Crash on the empty or first input, before mutation | Whether the harness handles zero-length data | Fix the harness; it blocks all deeper coverage |
| Crash in an API that takes a length and reads past it | The replay with the exact length | Fix the library regardless of the harness |
| No written precondition | Both the crash and the replay | File the missing contract along with the crash |

When a fuzzer crash is offered as the reproduction for a bug, the [guide to minimal reproductions](/learn/minimal-reproduction/) covers what else a reader needs. The ASan report format in these crashes is covered in the [guide to reading ASan reports](/learn/read-addresssanitizer-report/).

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Cut a reproduction down to one page](/learn/minimal-reproduction/)
    
    Broken dependencies The Proofline team November 22, 2026 3 min read
    
-   ### [Which stack in an AddressSanitizer report points at the bug?](/learn/read-addresssanitizer-report/)
    
    Code review The Proofline team November 25, 2026 5 min read
