Fix UTFDataFormatException on encoding long subplugin options.

ObjectOutputStream.writeUTF(String) has an unsigned short limit on
String length. On Projects with deep nested modules subplugin
options could produce String over this limit.

^KT-45202 Fixed
This commit is contained in:
bracadabra
2021-03-01 09:35:57 +03:00
committed by Yahor Berdnikau
parent f8ab16c823
commit b2372ff0b9
2 changed files with 9 additions and 2 deletions
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.gradle.tasks.CompilerPluginOptions
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.ObjectOutputStream
import java.nio.charset.StandardCharsets
import java.util.*
fun encodePluginOptions(options: Map<String, List<String>>): String {
@@ -35,7 +36,9 @@ fun encodePluginOptions(options: Map<String, List<String>>): String {
oos.writeInt(values.size)
for (value in values) {
oos.writeUTF(value)
val valueBytes = value.toByteArray(StandardCharsets.UTF_8)
oos.writeInt(valueBytes.size)
oos.write(valueBytes)
}
}