communicate: fix decodePayloadBody blank-guard bypass on CRLF branch
- Commit
74d67b6a8d21cd3219557334cd8f3a9a1a72f497- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-06 18:39 UTC (29 days ago)
- Parents
651c3e9
A trailing '.takeIf { ... } ?: return null' on an if/else-if/else chain binds
to the last else-branch only, so payloads containing CRLFCRLF skipped the
blank guard: blank bodies decoded to empty ByteArray instead of null, and
were passed into MLS/welcome crypto paths. Restructure with an explicit
intermediate val so the guard applies to all branches, and map empty
decodes to null. Caught by RcsInboundHelpersSlice4Test.
(cherry picked from commit c47e78488e11e40f5aeda8e18d9534064ff5a7d0)Diff
communicate/src/main/java/com/vayunmathur/communicate/telephony/RcsInboundParse.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/RcsInboundParse.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/RcsInboundParse.ktindex d81d4e7835..9515993d51 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/RcsInboundParse.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/RcsInboundParse.kt@@ -356,16 +356,20 @@ internal fun bufferLargeChunk( /** Base64-decode a CPIM-wrapped binary payload body. */ internal fun decodePayloadBody(body: String): ByteArray? {- val b64 = if (body.contains("\r\n\r\n")) {- body.substringAfter("\r\n\r\n", "").trim()+ // NOTE: kept as a separate val (not `...}.takeIf { ... }` on the if-chain):+ // a trailing call binds to the last else-branch only, silently skipping the+ // blank guard for the CRLF branch.+ val afterGap = if (body.contains("\r\n\r\n")) {+ body.substringAfter("\r\n\r\n", "") } else if (body.contains("\n\n")) {- body.substringAfter("\n\n", "").trim()+ body.substringAfter("\n\n", "") } else {- body.trim()- }.takeIf { it.isNotEmpty() } ?: return null+ body+ }+ val b64 = afterGap.trim().takeIf { it.isNotEmpty() } ?: return null return runCatching { android.util.Base64.decode(b64, android.util.Base64.DEFAULT)- }.getOrNull()+ }.getOrNull()?.takeIf { it.isNotEmpty() } } /**