From e764403cb21ee433945ee4dd8ac63c1a0767bb15 Mon Sep 17 00:00:00 2001 From: Graham Date: Wed, 2 Sep 2020 22:07:35 +0100 Subject: [PATCH] Add tests for corrupt containers Signed-off-by: Graham --- .../dev/openrs2/cache/Js5CompressionTest.kt | 65 ++++++++++++++++++ .../openrs2/cache/compression/bzip2-eof.dat | Bin 0 -> 55 bytes .../openrs2/cache/compression/gzip-eof.dat | Bin 0 -> 36 bytes .../cache/compression/invalid-length.dat | Bin 0 -> 5 bytes .../cache/compression/invalid-type.dat | Bin 0 -> 9 bytes .../invalid-uncompressed-length.dat | Bin 0 -> 9 bytes .../openrs2/cache/compression/lzma-eof.dat | Bin 0 -> 26 bytes .../openrs2/cache/compression/none-eof.dat | Bin 0 -> 12 bytes 8 files changed, 65 insertions(+) create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/bzip2-eof.dat create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/gzip-eof.dat create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/invalid-length.dat create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/invalid-type.dat create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/invalid-uncompressed-length.dat create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/lzma-eof.dat create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/none-eof.dat 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 0000000000000000000000000000000000000000..9909b51462d3ac59d8bb1ddc519e74c25bfa8113 GIT binary patch literal 55 zcmZQ%U|`S#Vh%&cNVVX|_L$^sAg{kc07%YYU}AJ&P+(A!N)BjaT+Q&YTqU@blcV&Q G*#-a$;S5&* literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..87bee8557c5613f59a70e68e93189c375f5989ce GIT binary patch literal 36 pcmZQ#U|^62Vh;Ik4hFl05z$P{pY=V?a&wt6F}&uApTQ240|0Bu2Ic?& literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..645f49c46678fc95e7ecbc2cf5db85704abfcd1a GIT binary patch literal 5 McmZQ*U|?VX00IR7fdBvi literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..4499cd8403db0097bf8adc16928706a921c89e05 GIT binary patch literal 9 KcmZQ!fC2yjEdT`o literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..c072da9e26932a3b16dc03a1cfd5c4caa5068765 GIT binary patch literal 9 NcmZQ%0D=Y}1^@yQ0D=Gj literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..dcd4e5eaeb89a0cbad9c62b7bd9c6ffcb104dda0 GIT binary patch literal 26 gcmZQ(U|