From e1f1da1cc0618afd7904d362b318187b0444cbe9 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 14 Feb 2021 20:09:34 +0000 Subject: [PATCH] Check that there is no trailing data after a group in CacheImporter Signed-off-by: Graham --- .../kotlin/org/openrs2/archive/cache/CacheImporter.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt index d2f2e4bd..83113f31 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt @@ -533,8 +533,14 @@ public class CacheImporter @Inject constructor( } } - val uncompressed = Js5Compression.uncompressUnlessEncrypted(buf.slice()) - return Group(archive, group, buf.retain(), uncompressed, version, versionTruncated) + val slice = buf.slice() + Js5Compression.uncompressUnlessEncrypted(slice).use { uncompressed -> + if (slice.isReadable) { + throw IOException("Trailing bytes after compressed data") + } + + return Group(archive, group, buf.retain(), uncompressed?.retain(), version, versionTruncated) + } } } catch (ex: IOException) { return null