From d2ee9d3b8b0bf6c6141a50a0ec8637b8f8176051 Mon Sep 17 00:00:00 2001 From: Graham Date: Wed, 2 Sep 2020 23:08:33 +0100 Subject: [PATCH] Check that all decompression algorithms throw IOException on failure Signed-off-by: Graham --- .../dev/openrs2/cache/Js5CompressionTest.kt | 27 ++++++++++++++++++ .../cache/compression/bzip2-corrupt.dat | Bin 0 -> 55 bytes .../cache/compression/gzip-corrupt.dat | Bin 0 -> 36 bytes .../cache/compression/lzma-corrupt.dat | Bin 0 -> 26 bytes 4 files changed, 27 insertions(+) create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/bzip2-corrupt.dat create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/gzip-corrupt.dat create mode 100644 cache/src/test/resources/dev/openrs2/cache/compression/lzma-corrupt.dat diff --git a/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt b/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt index b3954434..9d4b00fb 100644 --- a/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt +++ b/cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt @@ -320,6 +320,33 @@ object Js5CompressionTest { } } + @Test + fun testBzip2Corrupt() { + read("bzip2-corrupt.dat").use { compressed -> + assertThrows { + Js5Compression.uncompress(compressed).release() + } + } + } + + @Test + fun testGzipCorrupt() { + read("gzip-corrupt.dat").use { compressed -> + assertThrows { + Js5Compression.uncompress(compressed).release() + } + } + } + + @Test + fun testLzmaCorrupt() { + read("lzma-corrupt.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-corrupt.dat b/cache/src/test/resources/dev/openrs2/cache/compression/bzip2-corrupt.dat new file mode 100644 index 0000000000000000000000000000000000000000..b6fd1229a81988505bd6c088d49d03c53bff7dc3 GIT binary patch literal 55 zcmZQ%U|`S#V)p-zk!rz_?J>#OKwf`?0Fa!)z{KdlpunIcl^oEoSDVtCCJKZ6}82LOXj2gLvY literal 0 HcmV?d00001 diff --git a/cache/src/test/resources/dev/openrs2/cache/compression/lzma-corrupt.dat b/cache/src/test/resources/dev/openrs2/cache/compression/lzma-corrupt.dat new file mode 100644 index 0000000000000000000000000000000000000000..e2754a19880369eec789e9c5489233ced2abf15d GIT binary patch literal 26 gcmZQ(U|T@`j^WXos`L6{7061I*;Q#;t literal 0 HcmV?d00001