From df9c858131838c7fffcf4f793cee6dc4fe504dc9 Mon Sep 17 00:00:00 2001
From: Torsten Grote <t@grobox.de>
Date: Fri, 4 Nov 2022 13:57:42 -0300
Subject: [PATCH] Add more explicit bounds checks for unread post finding

---
 .../org/briarproject/briar/desktop/forums/PostsState.kt       | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/forums/PostsState.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/forums/PostsState.kt
index 2c99b09c19..2996d0c2da 100644
--- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/forums/PostsState.kt
+++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/forums/PostsState.kt
@@ -32,7 +32,7 @@ class Loaded(
 
     @UiExecutor
     fun unreadBeforeIndex(index: Int): UnreadPostInfo {
-        if (index <= 0) return UnreadPostInfo(null, 0)
+        if (index <= 0 || index >= posts.size) return UnreadPostInfo(null, 0)
 
         var lastUnread: Int? = null
         var num = 0
@@ -45,7 +45,7 @@ class Loaded(
 
     @UiExecutor
     fun unreadAfterIndex(index: Int): UnreadPostInfo {
-        if (index == -1) return UnreadPostInfo(null, 0)
+        if (index < 0 || index >= posts.size) return UnreadPostInfo(null, 0)
 
         var firstUnread: Int? = null
         var num = 0
-- 
GitLab