Modern Apps git

← Modern-Apps.git

communicate: fix MSRP delivery for chunks without Content-Length

Commit
e0979dd18f18d882a557b23cd7763902e2d80bb5
Author
Vayun Mathur <[email protected]>
When
2026-11-07 08:24 UTC (29 days ago)
Parents
6a40b43
handleSendFrame always consumed one more line after the body. On the
end-marker path that line is the next frame's start line, so a chunk
without a Content-Length header (the shape RcsMsrpFraming.splitSend
produces) was not delivered until another frame arrived, and that
frame was then corrupted. Only consume the marker line on the
Content-Length path, where it is still queued.

readToEndMarker also kept the framing CRLF before the end-marker in
the delivered body; drop exactly one so delivered bytes match the
bytes sent.

Found by RcsSlice3Pass2MsrpTest loopback tests, which failed before
this fix (inbound SEND never delivered) and pass after.

(cherry picked from commit 5a6789e7161e01e95611715e6b85f40504db3caf)

Diff

communicate/src/main/java/com/vayunmathur/communicate/data/rcs/RcsMsrp.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/rcs/RcsMsrp.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/rcs/RcsMsrp.ktindex db9e588235..69eb18b446 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/rcs/RcsMsrp.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/rcs/RcsMsrp.kt@@ -390,8 +390,11 @@ object RcsMsrp {         } else {             readToEndMarker(input, txid)         }-        // Consume the end-marker line.-        runCatching { input.readLine() }+        // Consume the end-marker line — but only on the Content-Length path,+        // where it is still queued. readToEndMarker already consumed it, so+        // consuming again there would eat the next frame's start line and+        // park delivery until another frame arrives.+        if (contentLength >= 0) runCatching { input.readLine() }         conn.lastActivityMs = System.currentTimeMillis()         // Keepalive empty SEND (§2.5): ack quietly, no delivery.         val range = headers["byte-range"]@@ -499,6 +502,9 @@ object RcsMsrp {                 if (line == null || line.startsWith("-------$txid")) break                 sb.append(line).append("\r\n")             }+            // The CRLF immediately before the end-marker is framing, not+            // body: drop exactly one so delivered bytes match what was sent.+            if (sb.endsWith("\r\n")) sb.setLength(sb.length - 2)             sb.toString().toByteArray(Charsets.UTF_8)         }.getOrNull()     }