From efc7ba9d2bdb76d47c72bc3163e3d4e90c77d505 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 12 Sep 2020 23:16:51 +0100 Subject: [PATCH] Add underflow/overflow tests Signed-off-by: Graham --- .../dev/openrs2/cache/Js5CompressionTest.kt | 31 ++++++++++++++++++ .../compression/compressed-underflow.dat | Bin 0 -> 36 bytes .../compression/uncompressed-overflow.dat | Bin 0 -> 36 bytes .../compression/uncompressed-underflow.dat | Bin 0 -> 36 bytes 4 files changed, 31 insertions(+) create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/compressed-underflow.dat create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/uncompressed-overflow.dat create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/uncompressed-underflow.dat diff --git a/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt b/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt index 7c7978368c..cabb250e02 100644 --- a/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt +++ b/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt @@ -466,6 +466,37 @@ object Js5CompressionTest { } } + @Test + fun testCompressedUnderflow() { + read("compressed-underflow.dat").use { compressed -> + assertThrows { + Js5Compression.uncompress(compressed.slice()).release() + } + + assertThrows { + Js5Compression.isKeyValid(compressed.slice(), XteaKey.ZERO) + } + } + } + + @Test + fun testUncompressedOverflow() { + read("uncompressed-overflow.dat").use { compressed -> + assertThrows { + Js5Compression.uncompress(compressed).release() + } + } + } + + @Test + fun testUncompressedUnderflow() { + read("uncompressed-underflow.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/compressed-underflow.dat b/cache/src/test/resources/dev/openrs2/cache/compression/compressed-underflow.dat new file mode 100644 index 0000000000000000000000000000000000000000..1c932178dc8f104b013675f13e821df19805206c GIT binary patch literal 36 pcmZQ#U|^5|Vs`m%4hFl05z$P{pY=V?a&wt6F}&uApTQ240|0By2Ic?& literal 0 HcmV?d00001 diff --git a/cache/src/test/resources/dev/openrs2/cache/compression/uncompressed-overflow.dat b/cache/src/test/resources/dev/openrs2/cache/compression/uncompressed-overflow.dat new file mode 100644 index 0000000000000000000000000000000000000000..62ed0c643387c9bbee89ba3a3131c428555d4032 GIT binary patch literal 36 pcmZQ#U|^62VmA414hFl05z$P{pY=V?a&wt6F}&uApTQ240|0B02IK$$ literal 0 HcmV?d00001 diff --git a/cache/src/test/resources/dev/openrs2/cache/compression/uncompressed-underflow.dat b/cache/src/test/resources/dev/openrs2/cache/compression/uncompressed-underflow.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