diff --git a/bitchat/Services/BLEService.swift b/bitchat/Services/BLEService.swift index 019a13da..7782ae69 100644 --- a/bitchat/Services/BLEService.swift +++ b/bitchat/Services/BLEService.swift @@ -15,6 +15,12 @@ struct NotificationStreamAssembler { buffer.append(chunk) + if buffer.count > TransportConfig.bleNotificationAssemblerHardCapBytes { + SecureLogger.error("❌ Notification assembler overflow (\(buffer.count) bytes); dropping partial frame", category: .session) + buffer.removeAll(keepingCapacity: false) + return ([], [], true) + } + var frames: [Data] = [] var dropped: [UInt8] = [] var reset = false diff --git a/bitchat/Services/TransportConfig.swift b/bitchat/Services/TransportConfig.swift index 0d0ea6c5..daf160f6 100644 --- a/bitchat/Services/TransportConfig.swift +++ b/bitchat/Services/TransportConfig.swift @@ -30,6 +30,7 @@ enum TransportConfig { static let bleDynamicRSSIThresholdDefault: Int = -90 static let bleConnectionCandidatesMax: Int = 100 static let blePendingWriteBufferCapBytes: Int = 1_000_000 + static let bleNotificationAssemblerHardCapBytes: Int = 8 * 1024 * 1024 static let blePendingNotificationsCapCount: Int = 20 // Nostr