ByteMutator

Structure-unaware mutations of byte strings, for fuzz tests of decoders: bit flips, replaced, inserted and deleted bytes, duplicated prefixes and truncation. Start from valid encodings (RFC test vectors are ideal seeds) so mutations reach deep into the parser, and use a seeded Random so a failure reproduces.

val random = Random(1)
repeat(5_000) {
val input = ByteMutator.mutate(validMessage, random)
try { decode(input) } catch (_: MyFormatException) { } // anything else is a bug
}

Functions

Link copied to clipboard
fun mutate(seed: ByteArray, random: Random): ByteArray

One to three mutations of seed; the seed itself is not changed.