From f61dcf37a89f3ec0c5205d0972bc76adc6cd1e0a Mon Sep 17 00:00:00 2001 From: ecgang Date: Sun, 2 Aug 2026 10:24:23 -0700 Subject: [PATCH] Log the oversized-payload rejection instead of dropping in silence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `decodeCore` rejects a compressed packet whose declared expanded size exceeds `maxFramedFileBytes` by returning nil with no trace. The suspicious- ratio rejection immediately below it drops the packet just as completely but logs a warning, so of the two ways a compressed payload can be refused, one is diagnosable and one is invisible. That asymmetry has a cost now that #1618 reports Android permitting a 10 MiB expanded payload against this ~1.13 MiB ceiling: every such message dies here with nothing on either side to say why, which is why it took a code read rather than a log to find. Behavior is unchanged — the packet is still refused, and the existing "Reject payloads larger than the framed file cap" test still covers it. Co-Authored-By: Claude Opus 5 (1M context) --- .../Sources/BitFoundation/BinaryProtocol.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/localPackages/BitFoundation/Sources/BitFoundation/BinaryProtocol.swift b/localPackages/BitFoundation/Sources/BitFoundation/BinaryProtocol.swift index e326eed2..030fab65 100644 --- a/localPackages/BitFoundation/Sources/BitFoundation/BinaryProtocol.swift +++ b/localPackages/BitFoundation/Sources/BitFoundation/BinaryProtocol.swift @@ -366,7 +366,19 @@ public struct BinaryProtocol { guard let rawSize = read16() else { return nil } originalSize = Int(rawSize) } - guard originalSize >= 0 && originalSize <= FileTransferLimits.maxFramedFileBytes else { return nil } + // Logged, not silent: this is the sibling of the ratio + // rejection below and drops the packet just as completely, but + // returning `nil` bare left no trace anywhere. A peer whose + // ceiling is higher than ours (issue #1618: Android permits a + // 10 MiB expanded payload against our ~1.13 MiB) then looks to + // both sides like a message that simply never arrived. + guard originalSize >= 0 && originalSize <= FileTransferLimits.maxFramedFileBytes else { + SecureLogger.warning( + "🚫 Declared expanded payload \(originalSize) B exceeds the \(FileTransferLimits.maxFramedFileBytes) B ceiling", + category: .security + ) + return nil + } let compressedSize = payloadLength - lengthFieldBytes guard compressedSize > 0, let compressed = readData(compressedSize) else { return nil }