diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/StarboundPak.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/StarboundPak.kt index 9d4a5716..2a90f9fa 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/StarboundPak.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/StarboundPak.kt @@ -194,6 +194,7 @@ class StarboundPak(val path: File, callback: (finished: Boolean, status: String) // long (offset от начала файла) // long (длина файла) val stream = DataInputStream(BufferedInputStream(Channels.newInputStream(reader.channel), 2 shl 22)) + val flength = reader.length() for (i in 0 until indexNodeCount) { var name: String? = null @@ -207,11 +208,11 @@ class StarboundPak(val path: File, callback: (finished: Boolean, status: String) val offset = stream.readLong() val length = stream.readLong() - if (offset > reader.length()) { + if (offset > flength) { throw IndexOutOfBoundsException("Garbage offset at index $i: ${offset}") } - if (length + offset > reader.length()) { + if (length + offset > flength) { throw IndexOutOfBoundsException("Garbage offset + length at index $i: ${length + offset}") }