diff --git a/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt b/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt index 723e4fd184..eb86f32087 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 0000000000..9909b51462 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 0000000000..87bee8557c 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 0000000000..645f49c466 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 0000000000..4499cd8403 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 0000000000..c072da9e26 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 0000000000..dcd4e5eaeb 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 0000000000..fa2e414ed7 Binary files /dev/null and b/cache/src/test/resources/dev/openrs2/cache/compression/none-eof.dat differ