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:
committed by
Yahor Berdnikau
parent
f8ab16c823
commit
b2372ff0b9
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.utils
|
|||||||
|
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
import java.io.ObjectInputStream
|
import java.io.ObjectInputStream
|
||||||
|
import java.nio.charset.StandardCharsets
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun decodePluginOptions(options: String): Map<String, List<String>> {
|
fun decodePluginOptions(options: String): Map<String, List<String>> {
|
||||||
@@ -36,7 +37,10 @@ fun decodePluginOptions(options: String): Map<String, List<String>> {
|
|||||||
val values = mutableListOf<String>()
|
val values = mutableListOf<String>()
|
||||||
|
|
||||||
repeat(valueCount) {
|
repeat(valueCount) {
|
||||||
values += ois.readUTF()
|
val size = ois.readInt()
|
||||||
|
val byteArray = ByteArray(size)
|
||||||
|
ois.readFully(byteArray)
|
||||||
|
values += String(byteArray, StandardCharsets.UTF_8)
|
||||||
}
|
}
|
||||||
|
|
||||||
map[key] = values
|
map[key] = values
|
||||||
|
|||||||
+4
-1
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.gradle.tasks.CompilerPluginOptions
|
|||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.ObjectOutputStream
|
import java.io.ObjectOutputStream
|
||||||
|
import java.nio.charset.StandardCharsets
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun encodePluginOptions(options: Map<String, List<String>>): String {
|
fun encodePluginOptions(options: Map<String, List<String>>): String {
|
||||||
@@ -35,7 +36,9 @@ fun encodePluginOptions(options: Map<String, List<String>>): String {
|
|||||||
|
|
||||||
oos.writeInt(values.size)
|
oos.writeInt(values.size)
|
||||||
for (value in values) {
|
for (value in values) {
|
||||||
oos.writeUTF(value)
|
val valueBytes = value.toByteArray(StandardCharsets.UTF_8)
|
||||||
|
oos.writeInt(valueBytes.size)
|
||||||
|
oos.write(valueBytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user