[JPS] Improved processing of broken caches

If serialized metadata version has evidently incorrect size the module
should be marked for rebuild prior to reading serialized version.

#KT-42194 Fixed
This commit is contained in:
Andrey Uskov
2021-09-20 09:58:42 +03:00
committed by teamcityserver
parent 5d56bd545e
commit 4ad828f80f
2 changed files with 12 additions and 2 deletions
@@ -39,7 +39,11 @@ class ModuleMapping private constructor(
fun readVersionNumber(stream: DataInputStream): IntArray? =
try {
IntArray(stream.readInt()) { stream.readInt() }
val size = stream.readInt()
if (size < 0 || size > BinaryVersion.MAX_LENGTH)
null // cache is evidently corrupted
else
IntArray(size) { stream.readInt() }
} catch (e: IOException) {
null
}
@@ -18,7 +18,12 @@ abstract class BinaryVersion(private vararg val numbers: Int) {
val major: Int = numbers.getOrNull(0) ?: UNKNOWN
val minor: Int = numbers.getOrNull(1) ?: UNKNOWN
val patch: Int = numbers.getOrNull(2) ?: UNKNOWN
val rest: List<Int> = if (numbers.size > 3) numbers.asList().subList(3, numbers.size).toList() else emptyList()
val rest: List<Int> = if (numbers.size > 3) {
if (numbers.size > MAX_LENGTH)
throw IllegalArgumentException("BinaryVersion with length more than $MAX_LENGTH are not supported. Provided length ${numbers.size}.")
else
numbers.asList().subList(3, numbers.size).toList()
} else emptyList()
abstract fun isCompatible(): Boolean
@@ -80,6 +85,7 @@ abstract class BinaryVersion(private vararg val numbers: Int) {
}
companion object {
const val MAX_LENGTH = 1024
private const val UNKNOWN = -1
@JvmStatic