From b067020cad8d47c00d9c8f3b787b101a642bb0a2 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 14 Feb 2021 18:57:22 +0000 Subject: [PATCH] Ignore trailing blocks with a non-zero next block pointer While the client doesn't appear to be capable of producing a trailing block with a non-zero next block pointer (though I may have misread the code), there are caches out there in the wild with trailing non-zero next block pointers. When it is reading a group, the client ignores these. Therefore, for compatibility with the client and existing caches, this commit removes the StoreCorruptException thrown in this case. Signed-off-by: Graham --- .../main/kotlin/org/openrs2/cache/DiskStore.kt | 4 ---- .../kotlin/org/openrs2/cache/DiskStoreTest.kt | 17 +++++++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cache/src/main/kotlin/org/openrs2/cache/DiskStore.kt b/cache/src/main/kotlin/org/openrs2/cache/DiskStore.kt index a2f0e83a..e1ad1dfe 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/DiskStore.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/DiskStore.kt @@ -196,10 +196,6 @@ public class DiskStore private constructor( num++ } while (buf.isWritable) - if (block != 0) { - throw StoreCorruptException("Group longer than expected") - } - return buf.retain() } } diff --git a/cache/src/test/kotlin/org/openrs2/cache/DiskStoreTest.kt b/cache/src/test/kotlin/org/openrs2/cache/DiskStoreTest.kt index 8a3bee7e..b50e4a93 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/DiskStoreTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/DiskStoreTest.kt @@ -495,12 +495,6 @@ class DiskStoreTest { @Test fun testReadCorrupt() { - readTest("corrupt-eof-late") { store -> - assertFailsWith { - store.read(255, 1).release() - } - } - readTest("corrupt-first-eof-early") { store -> assertFailsWith { store.read(255, 1).release() @@ -562,6 +556,17 @@ class DiskStoreTest { } } + @Test + fun testReadCorruptEofLate() { + readTest("corrupt-eof-late") { store -> + copiedBuffer("OpenRS2".repeat(1000)).use { expected -> + store.read(255, 1).use { actual -> + assertEquals(expected, actual) + } + } + } + } + @Test fun testOverwriteCorrupt() { overwriteTest("corrupt-eof-late", "corrupt-eof-late-overwritten") { store ->