mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-11-01 07:53:26 +00:00
Merge d32021049e1b053cabe765374343fc72b161da35 into 9b84b361225facd8e623f25d76f889d3dc54a879
This commit is contained in:
commit
9b1f280821
@ -7,15 +7,9 @@ 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
|
||||
}()
|
||||
/// Note: This is now a hard expanded-size ceiling rather than the old tlv+frame formula.
|
||||
/// 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
|
||||
|
||||
@ -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, version: 2)
|
||||
|
||||
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 {
|
||||
|
||||
@ -56,7 +56,8 @@ final class TestHelpers {
|
||||
recipientID: PeerID? = nil,
|
||||
payload: Data = Data("test payload".utf8),
|
||||
signature: Data? = nil,
|
||||
ttl: UInt8 = 3
|
||||
ttl: UInt8 = 3,
|
||||
version: UInt8 = 1
|
||||
) -> BitchatPacket {
|
||||
return BitchatPacket(
|
||||
type: type,
|
||||
@ -65,7 +66,8 @@ final class TestHelpers {
|
||||
timestamp: UInt64(Date().timeIntervalSince1970 * 1000),
|
||||
payload: payload,
|
||||
signature: signature,
|
||||
ttl: ttl
|
||||
ttl: ttl,
|
||||
version: version
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user