Fix: Prevent potential buffer overflow in CompressionUtil.swift

This commit is contained in:
mirza-samad-ahmed-baig
2025-07-09 15:51:48 +05:00
parent 5ec79e8080
commit 653f2b2812
+2 -1
View File
@@ -18,7 +18,8 @@ struct CompressionUtil {
// Skip compression for small data // Skip compression for small data
guard data.count >= compressionThreshold else { return nil } guard data.count >= compressionThreshold else { return nil }
let destinationBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: data.count) let maxCompressedSize = data.count + (data.count / 255) + 16
let destinationBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: maxCompressedSize)
defer { destinationBuffer.deallocate() } defer { destinationBuffer.deallocate() }
let compressedSize = data.withUnsafeBytes { sourceBuffer in let compressedSize = data.withUnsafeBytes { sourceBuffer in