diff --git a/bitchat/Utils/CompressionUtil.swift b/bitchat/Utils/CompressionUtil.swift index e112e977..4fabf38a 100644 --- a/bitchat/Utils/CompressionUtil.swift +++ b/bitchat/Utils/CompressionUtil.swift @@ -18,7 +18,8 @@ struct CompressionUtil { // Skip compression for small data guard data.count >= compressionThreshold else { return nil } - let destinationBuffer = UnsafeMutablePointer.allocate(capacity: data.count) + let maxCompressedSize = data.count + (data.count / 255) + 16 + let destinationBuffer = UnsafeMutablePointer.allocate(capacity: maxCompressedSize) defer { destinationBuffer.deallocate() } let compressedSize = data.withUnsafeBytes { sourceBuffer in