Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FerrumBrain committed Feb 27, 2025
1 parent 687adb0 commit a8380c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import java.nio.file.Path
import java.security.MessageDigest
import kotlin.io.path.writeText

class ByteArrayReproducerWriter(private val template: ReproducerTestTemplate, private val method: Method) : CrashReproducerWriter {
class ByteArrayReproducerWriter(private val template: ReproducerTestTemplate, private val method: Method) :
CrashReproducerWriter(template, method) {
@OptIn(ExperimentalStdlibApi::class)
override fun writeToFile(input: ByteArray, reproducerFile: Path) {
val instanceName = method.declaringClass.kotlin.objectInstance?.let {
method.declaringClass.kotlin.simpleName
} ?: "${method.declaringClass.kotlin.simpleName}::class.java.getDeclaredConstructor().newInstance()"

val code = CodeBlock.builder()
.addStatement(
"$instanceName.`${method.name}`(KFuzzerImpl(byteArrayOf(${input.joinToString(", ")})))",
"${method.getInstanceString()}.`${method.name}`(KFuzzerImpl(byteArrayOf(${input.joinToString(", ")})))",
)
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kotlinx.fuzz.reproduction
import java.lang.reflect.Method
import java.nio.file.Path

interface CrashReproducerWriter {
abstract class CrashReproducerWriter(private val template: ReproducerTestTemplate, private val method: Method) {
fun registerOutputs(instance: Any, method: Method, input: ByteArray): List<ExecutionResult> {
val fuzzer = KFuzzerRegisteringImpl(input)
try {
Expand All @@ -12,5 +12,13 @@ interface CrashReproducerWriter {
return fuzzer.values
}
}
fun writeToFile(input: ByteArray, reproducerFile: Path)

private fun Method.isDeclaredInObject() = this.declaringClass.kotlin.objectInstance != null
protected fun Method.getInstanceString() = if (isDeclaredInObject()) {
method.declaringClass.kotlin.simpleName
} else {
"${method.declaringClass.kotlin.simpleName}::class.java.getDeclaredConstructor().newInstance()"
}

abstract fun writeToFile(input: ByteArray, reproducerFile: Path)
}

0 comments on commit a8380c7

Please sign in to comment.