From ffa7f0361f8058e33a3d3c1d4b92308d6c8d87db Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 10 Feb 2024 21:23:55 +0700 Subject: [PATCH] Make readVarLongInfo account for stream end --- gradle.properties | 2 +- .../kotlin/ru/dbotthepony/kommons/io/InputStreamUtils.kt | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 4f78a11..ea97363 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ kotlin.code.style=official specifyKotlinAsDependency=false projectGroup=ru.dbotthepony.kommons -projectVersion=2.1.3 +projectVersion=2.1.5 guavaDepVersion=33.0.0 gsonDepVersion=2.8.9 diff --git a/src/main/kotlin/ru/dbotthepony/kommons/io/InputStreamUtils.kt b/src/main/kotlin/ru/dbotthepony/kommons/io/InputStreamUtils.kt index 7ec55a7..c232d21 100644 --- a/src/main/kotlin/ru/dbotthepony/kommons/io/InputStreamUtils.kt +++ b/src/main/kotlin/ru/dbotthepony/kommons/io/InputStreamUtils.kt @@ -85,6 +85,9 @@ private fun readVarLongInfo(supplier: IntSupplier): VarLongReadResult { var read = supplier.asInt var i = 1 + if (read == -1) + throw EOFException() + while (true) { result = (result shl 7) or (read.toLong() and 0x7F) @@ -92,6 +95,10 @@ private fun readVarLongInfo(supplier: IntSupplier): VarLongReadResult { break read = supplier.asInt + + if (read == -1) + throw EOFException("Reached end of stream before finished reading variable length integer (read totally $i bytes)") + i++ }