Merge pull request #96 from Mirza-Samad-Ahmed-Baig/fix/compression-buffer-overflow

Fix: Prevent potential buffer overflow in CompressionUtil.swift
This commit is contained in:
jack
2025-07-09 16:31:39 +02:00
committed by GitHub
+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