Fuzzing a PDF parser: three levels and a set of oracles

Generated broken files, per-layer fuzzing, and oracles that check the answer is right.

Not crashing is the easy half of robustness. The hard half is not quietly giving the wrong answer, and that needs different tests.

1. Generated broken documents

Random bytes get rejected in the first few hundred bytes, so the deep code never runs. Instead, a generator builds valid skeletons and corrupts them on purpose: truncation, bad xref offsets, negative stream lengths, dangling and circular references, deep nesting. That exercises the recovery paths real damaged files hit, like a broken cross-reference table.

2. Fuzzing each layer

Whole-file fuzzing barely reaches the decoders, so they're fuzzed directly. That's also where resource limits matter: a 100 GB stream doesn't crash, it hangs, and a hang in a request handler is an outage. A cap turns it into a failed check.

3. Oracles

Checks that the answer is right, whatever the input:

  • Determinism The same file verifies the same way, byte for byte. Catches map ordering and uninitialised state.
  • Re-verification A conversion reported valid must verify as valid independently.
  • Convergence The fix loop must terminate, so one fix can't keep undoing another.
  • A second implementation Every veraPDF corpus file goes through gopdfrab and veraPDF, and any disagreement fails the build.

Why it matters

A validator runs on documents you don't trust yet, so it must not fall over. Typed errors keep "this file is damaged" and "this file fails PDF/A" as different results.

← All posts