Skip to content

JetBrains-Research/kotlinx.fuzz

Repository files navigation

kotlinx.fuzz

kotlinx.fuzz is a general purpose fuzzing library for Kotlin

Usage

  1. Add PLAN lab maven repository to your gradle config:

build.gradle.kts:

repositories {
    maven(url = "https://plan-maven.apal-research.com")
}

settings.gradle.kts:

pluginManagement {
    repositories {
        maven(url = "https://plan-maven.apal-research.com")
    }
}
  1. Add kotlinx.fuzz as a dependency:
dependencies {
    testRuntimeOnly("org.jetbrains:kotlinx.fuzz.jazzer:0.1.0")
}
  1. Apply kotlinx.fuzz plugin to your project:
plugins {
    id("kotlinx.fuzz.gradle") version "0.1.0"
}
  1. Configure plugin:
fuzzConfig {
    instrument = listOf("org.example.**")
    maxSingleTargetFuzzTime = 10.seconds
}
  1. Write your fuzz tests:
package org.example

import kotlinx.fuzz.KFuzzTest
import kotlinx.fuzz.KFuzzer

object ExampleTest {
    @KFuzzTest
    fun foo(data: KFuzzer) {
        if (data.int() % 2 == 0) {
            if (data.int() % 3 == 2) {
                if (data.int() % 31 == 11) {
                    throw IllegalArgumentException()
                }
            }
        }
    }
}
  1. Run fuzzer:
~/example » ./gradlew fuzz                                                                                                                                                  1 ↵

> Task fuzz

SampleTarget > public final void org.example.ExampleTest.foo(kotlinx.fuzz.KFuzzer) FAILED
    java.lang.IllegalArgumentException
        at org.example.ExampleTest.foo(ExampleTest.kt:12)
  1. Check the fuzzing report in build/fuzz

You can see more examples of kotlinz.fuzz usage in kotlinx.fuzz.test