Fix JS5 uncompression of large GZIP-compressed files

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 4 years ago
parent 415363fbbe
commit e5e9ece098
  1. 10
      cache/src/main/java/dev/openrs2/cache/Js5Compression.kt
  2. 11
      cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt
  3. BIN
      cache/src/test/resources/dev/openrs2/cache/compression/gzip-large.dat
  4. 1
      cache/src/test/resources/dev/openrs2/cache/compression/large.dat

@ -7,6 +7,7 @@ import dev.openrs2.crypto.xteaEncrypt
import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufInputStream
import io.netty.buffer.ByteBufOutputStream
import java.io.EOFException
public object Js5Compression {
public fun compress(input: ByteBuf, type: Js5CompressionType, key: XteaKey = XteaKey.ZERO): ByteBuf {
@ -102,7 +103,14 @@ public object Js5Compression {
plaintext.alloc().buffer(uncompressedLen, uncompressedLen).use { output ->
type.createInputStream(ByteBufInputStream(plaintext, len), uncompressedLen).use { inputStream ->
output.writeBytes(inputStream, uncompressedLen)
var remaining = uncompressedLen
while (remaining > 0) {
val n = output.writeBytes(inputStream, remaining)
if (n == -1) {
throw EOFException()
}
remaining -= n
}
}
return output.retain()

@ -55,6 +55,17 @@ object Js5CompressionTest {
}
}
@Test
fun testUncompressLargeGzip() {
read("gzip-large.dat").use { input ->
Js5Compression.uncompress(input).use { actual ->
read("large.dat").use { expected ->
assertEquals(expected, actual)
}
}
}
}
@Test
fun testCompressBzip2() {
Unpooled.wrappedBuffer("OpenRS2".toByteArray()).use { expected ->

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save