From 5a20b75f4f0feb6e13b2f8cded6678a5f49719f3 Mon Sep 17 00:00:00 2001 From: Graham Date: Wed, 2 Sep 2020 23:11:46 +0100 Subject: [PATCH] Use Preconditions.checkPositionIndexes() in ByteBuf.crc32() Signed-off-by: Graham --- buffer/build.gradle.kts | 2 ++ buffer/src/main/java/dev/openrs2/buffer/ByteBufExtensions.kt | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/buffer/build.gradle.kts b/buffer/build.gradle.kts index 28cb511183..6863d0af35 100644 --- a/buffer/build.gradle.kts +++ b/buffer/build.gradle.kts @@ -5,6 +5,8 @@ plugins { dependencies { api("io.netty:netty-buffer:${Versions.netty}") + + implementation("com.google.guava:guava:${Versions.guava}") } publishing { diff --git a/buffer/src/main/java/dev/openrs2/buffer/ByteBufExtensions.kt b/buffer/src/main/java/dev/openrs2/buffer/ByteBufExtensions.kt index bbc531d484..6a94eaa33d 100644 --- a/buffer/src/main/java/dev/openrs2/buffer/ByteBufExtensions.kt +++ b/buffer/src/main/java/dev/openrs2/buffer/ByteBufExtensions.kt @@ -1,5 +1,6 @@ package dev.openrs2.buffer +import com.google.common.base.Preconditions import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBufUtil import java.util.zip.CRC32 @@ -85,9 +86,7 @@ public fun ByteBuf.crc32(): Int { } public fun ByteBuf.crc32(index: Int, len: Int): Int { - if (index < 0 || index >= capacity() || len < 0 || (index + len) >= capacity()) { - throw IndexOutOfBoundsException() - } + Preconditions.checkPositionIndexes(index, index + len, capacity()) val crc = CRC32() val count = nioBufferCount()