From 653f2b28125e26671c37ee79fee9d86b6516b104 Mon Sep 17 00:00:00 2001 From: mirza-samad-ahmed-baig Date: Wed, 9 Jul 2025 15:51:48 +0500 Subject: [PATCH] Fix: Prevent potential buffer overflow in CompressionUtil.swift --- bitchat/Utils/CompressionUtil.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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