mortie / jcof

An efficient drop-in replacement for JSON.
ISC License
153 stars 0 forks source link

Establish a fuzzing harness to demonstrate parser robustness #4

Open riking opened 2 years ago

riking commented 2 years ago

Running a fuzzer is a basic quality-of-implementation task for any parser that wants to be widely used. Because you have a canonical reference format, you can easily implement round-trip verification fuzzing.

// We can round-trip any valid JSON
function fuzzTargetA(payload) {
  const expected = try { JSON.parse(payload) } catch { return; };
  const result = jcof.decode(jcof.encode(expected));
  if (!check_equivalence(expected, result)) { fail(); }
}

// We can encode anything we successfully decode, and it decodes without errors
function fuzzTargetB(payload) {
  const expected = try { jcof.decode(payload) } catch { return; };
  const result = jcof.decode(jcof.encode(decoded));
  if (!check_equivalence(expected, result)) { fail(); }
}