jcof icon indicating copy to clipboard operation
jcof copied to clipboard

Establish a fuzzing harness to demonstrate parser robustness

Open riking opened this issue 3 years ago • 0 comments

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(); }
}

riking avatar Jul 17 '22 07:07 riking