diff --git a/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt b/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt index 723e4fd1..eb86f320 100644 --- a/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt +++ b/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt @@ -4,6 +4,8 @@ import dev.openrs2.buffer.use import dev.openrs2.crypto.XteaKey import io.netty.buffer.ByteBuf import io.netty.buffer.Unpooled +import org.junit.jupiter.api.assertThrows +import java.io.EOFException import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals @@ -255,6 +257,69 @@ object Js5CompressionTest { } } + @Test + fun testInvalidType() { + read("invalid-type.dat").use { compressed -> + assertThrows { + Js5Compression.uncompress(compressed).release() + } + } + } + + @Test + fun testInvalidLength() { + read("invalid-length.dat").use { compressed -> + assertThrows { + Js5Compression.uncompress(compressed).release() + } + } + } + + @Test + fun testInvalidUncompressedLength() { + read("invalid-uncompressed-length.dat").use { compressed -> + assertThrows { + Js5Compression.uncompress(compressed).release() + } + } + } + + @Test + fun testNoneEof() { + read("none-eof.dat").use { compressed -> + assertThrows { + Js5Compression.uncompress(compressed).release() + } + } + } + + @Test + fun testBzip2Eof() { + read("bzip2-eof.dat").use { compressed -> + assertThrows { + Js5Compression.uncompress(compressed).release() + } + } + } + + @Test + fun testGzipEof() { + read("gzip-eof.dat").use { compressed -> + assertThrows { + Js5Compression.uncompress(compressed).release() + } + } + } + + @Test + fun testLzmaEof() { + read("lzma-eof.dat").use { compressed -> + assertThrows { + Js5Compression.uncompress(compressed).release() + } + } + } + private fun read(name: String): ByteBuf { Js5CompressionTest::class.java.getResourceAsStream("compression/$name").use { input -> return Unpooled.wrappedBuffer(input.readAllBytes()) diff --git a/cache/src/test/resources/dev/openrs2/cache/compression/bzip2-eof.dat b/cache/src/test/resources/dev/openrs2/cache/compression/bzip2-eof.dat new file mode 100644 index 00000000..9909b514 Binary files /dev/null and b/cache/src/test/resources/dev/openrs2/cache/compression/bzip2-eof.dat differ diff --git a/cache/src/test/resources/dev/openrs2/cache/compression/gzip-eof.dat b/cache/src/test/resources/dev/openrs2/cache/compression/gzip-eof.dat new file mode 100644 index 00000000..87bee855 Binary files /dev/null and b/cache/src/test/resources/dev/openrs2/cache/compression/gzip-eof.dat differ diff --git a/cache/src/test/resources/dev/openrs2/cache/compression/invalid-length.dat b/cache/src/test/resources/dev/openrs2/cache/compression/invalid-length.dat new file mode 100644 index 00000000..645f49c4 Binary files /dev/null and b/cache/src/test/resources/dev/openrs2/cache/compression/invalid-length.dat differ diff --git a/cache/src/test/resources/dev/openrs2/cache/compression/invalid-type.dat b/cache/src/test/resources/dev/openrs2/cache/compression/invalid-type.dat new file mode 100644 index 00000000..4499cd84 Binary files /dev/null and b/cache/src/test/resources/dev/openrs2/cache/compression/invalid-type.dat differ diff --git a/cache/src/test/resources/dev/openrs2/cache/compression/invalid-uncompressed-length.dat b/cache/src/test/resources/dev/openrs2/cache/compression/invalid-uncompressed-length.dat new file mode 100644 index 00000000..c072da9e Binary files /dev/null and b/cache/src/test/resources/dev/openrs2/cache/compression/invalid-uncompressed-length.dat differ diff --git a/cache/src/test/resources/dev/openrs2/cache/compression/lzma-eof.dat b/cache/src/test/resources/dev/openrs2/cache/compression/lzma-eof.dat new file mode 100644 index 00000000..dcd4e5ea Binary files /dev/null and b/cache/src/test/resources/dev/openrs2/cache/compression/lzma-eof.dat differ diff --git a/cache/src/test/resources/dev/openrs2/cache/compression/none-eof.dat b/cache/src/test/resources/dev/openrs2/cache/compression/none-eof.dat new file mode 100644 index 00000000..fa2e414e Binary files /dev/null and b/cache/src/test/resources/dev/openrs2/cache/compression/none-eof.dat differ