From 81da576aa8cf0cc8451e769d5d848a723bdf5f74 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Fri, 9 Jan 2026 20:47:46 +0700 Subject: [PATCH] fix: deserialization issue with routed packets --- .../com/bitchat/android/protocol/BinaryProtocol.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/bitchat/android/protocol/BinaryProtocol.kt b/app/src/main/java/com/bitchat/android/protocol/BinaryProtocol.kt index dc9dce8a..e6243599 100644 --- a/app/src/main/java/com/bitchat/android/protocol/BinaryProtocol.kt +++ b/app/src/main/java/com/bitchat/android/protocol/BinaryProtocol.kt @@ -368,9 +368,16 @@ object BinaryProtocol { var routeCount = 0 if (hasRoute) { // Peek count (1 byte) without consuming buffer for now - val mark = buffer.position() - if (raw.size >= mark + 1) { - routeCount = raw[mark].toUByte().toInt() + // The buffer is currently positioned at the start of SenderID (after fixed header) + // We must skip SenderID and RecipientID (if present) to find the route count + val currentPos = buffer.position() + var routeOffset = currentPos + SENDER_ID_SIZE + if (hasRecipient) { + routeOffset += RECIPIENT_ID_SIZE + } + + if (raw.size >= routeOffset + 1) { + routeCount = raw[routeOffset].toUByte().toInt() } expectedSize += 1 + (routeCount * SENDER_ID_SIZE) }