fix: raise iOS max decompressed payload size to match Android (10 MiB)

iOS's FileTransferLimits.maxFramedFileBytes was 1,179,760 bytes (~1.13 MiB)
while Android's AppConstants.Protocol.MAX_PAYLOAD_LENGTH is 10,485,760 bytes
(10 MiB). Since both platforms already enforce the same 50,000:1 compression-
ratio guard independently, the lower iOS ceiling served no additional
protection — it just caused legitimate large compressed messages from Android
to be silently dropped on decode with no error surfaced to either side.

Raise iOS's limit to 10 MiB to match Android's intended design ceiling.

Fixes #1618
This commit is contained in:
Harsh Jain 2026-08-02 19:08:43 +05:30
parent 1f59e814f9
commit b30670a671
2 changed files with 13 additions and 9 deletions

View File

@ -7,15 +7,8 @@ public enum FileTransferLimits {
/// Compressed images after downscaling should comfortably fit under this budget.
public static let maxImageBytes: Int = 512 * 1024 // 512 KiB
/// Worst-case size once TLV metadata and binary packet framing are included for the largest payloads.
public static let maxFramedFileBytes: Int = {
let maxMetadataBytes = Int(UInt16.max) * 2 // fileName + mimeType TLVs
let tlvEnvelopeOverhead = 18 + maxMetadataBytes // TLV tags + lengths + metadata bytes
let binaryEnvelopeOverhead = BinaryProtocol.v2HeaderSize
+ BinaryProtocol.senderIDSize
+ BinaryProtocol.recipientIDSize
+ BinaryProtocol.signatureSize
return maxPayloadBytes + tlvEnvelopeOverhead + binaryEnvelopeOverhead
}()
/// MUST stay in sync with AppConstants.Protocol.MAX_PAYLOAD_LENGTH in the Android repo (issue #1618).
public static let maxFramedFileBytes: Int = 10_485_760
public static func isValidPayload(_ size: Int) -> Bool {
size <= maxPayloadBytes

View File

@ -350,6 +350,17 @@ struct BinaryProtocolTests {
#expect(BinaryProtocol.decode(encoded) == nil)
}
@Test("Regression test for issue #1618: decode payload between 1.13 MiB and 10 MiB")
func payloadSizeBetweenOldAndNewLimit() throws {
let payloadSize = 2_000_000
let payload = Data(repeating: 0x41, count: payloadSize)
let packet = TestHelpers.createTestPacket(payload: payload)
let encodedData = try #require(BinaryProtocol.encode(packet), "Failed to encode packet")
let decodedPacket = try #require(BinaryProtocol.decode(encodedData), "Failed to decode packet")
#expect(decodedPacket.payload == payload)
}
// MARK: - Message Padding Tests
@Test func messagePadding() throws {