From 078b1f619766ae7f20e5a46f85a56ba82365b59b Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 2 Apr 2022 12:37:22 +0100 Subject: [PATCH] Fix version trailers in RuneLiteStore Signed-off-by: Graham --- .../kotlin/org/openrs2/cache/RuneLiteStore.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cache/src/main/kotlin/org/openrs2/cache/RuneLiteStore.kt b/cache/src/main/kotlin/org/openrs2/cache/RuneLiteStore.kt index 137ae1d5..8ce5c8a3 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/RuneLiteStore.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/RuneLiteStore.kt @@ -100,7 +100,24 @@ public class RuneLiteStore @Inject constructor( "contents" -> { Unpooled.wrappedBuffer(Base64.getDecoder().decode(value)).use { buf -> - output.write(archive, group!!.id, buf) + // Some groups have version trailers and some don't. Fix that up here. + if (group!!.checksum != buf.crc32()) { + if (group!!.version != VersionTrailer.strip(buf)) { + throw StoreCorruptException("Group version does not match contents") + } + + if (group!!.checksum != buf.crc32()) { + throw StoreCorruptException("Group CRC does not match contents") + } + } + + alloc.buffer(2, 2).use { versionBuf -> + versionBuf.writeShort(group!!.version) + + Unpooled.wrappedBuffer(buf.retain(), versionBuf.retain()).use { combinedBuf -> + output.write(archive, group!!.id, combinedBuf) + } + } } }