diff --git a/Sources/Uploadcare/Uploadcare.swift b/Sources/Uploadcare/Uploadcare.swift index 6d7ca596..9898e001 100644 --- a/Sources/Uploadcare/Uploadcare.swift +++ b/Sources/Uploadcare/Uploadcare.swift @@ -52,7 +52,7 @@ public class Uploadcare: NSObject { /// Library name private var libraryName = "UploadcareSwift" /// Library version - private var libraryVersion = "0.8.1" + private var libraryVersion = "0.8.2" /// Performs network requests private let requestManager: RequestManager diff --git a/Sources/Uploadcare/Utils.swift b/Sources/Uploadcare/Utils.swift index 43915b05..1ded688f 100644 --- a/Sources/Uploadcare/Utils.swift +++ b/Sources/Uploadcare/Utils.swift @@ -41,35 +41,35 @@ func detectMimeType(for data: Data) -> String { var bytes = [UInt8].init(repeating: 0, count: data.count) data.copyBytes(to: &bytes, count: data.count) - if bytes[0...2] == [0xFF, 0xD8, 0xFF] { + if data.count > 2, bytes[0...2] == [0xFF, 0xD8, 0xFF] { return "image/jpeg" } - if bytes[0...3] == [0x89, 0x50, 0x4E, 0x47] { + if data.count > 3, bytes[0...3] == [0x89, 0x50, 0x4E, 0x47] { return "image/png" } - if bytes[0...2] == [0x47, 0x49, 0x46] { + if data.count > 2, bytes[0...2] == [0x47, 0x49, 0x46] { return "image/gif" } - if bytes[8...11] == [0x57, 0x45, 0x42, 0x50] { + if data.count > 11, bytes[8...11] == [0x57, 0x45, 0x42, 0x50] { return "image/webp" } - if (bytes[0...3] == [0x49, 0x49, 0x2A, 0x00] || bytes[0...3] == [0x4D, 0x4D, 0x00, 0x2A]) && bytes[8...9] == [0x43, 0x52] { + if data.count > 9, (bytes[0...3] == [0x49, 0x49, 0x2A, 0x00] || bytes[0...3] == [0x4D, 0x4D, 0x00, 0x2A]) && bytes[8...9] == [0x43, 0x52] { return "image/x-canon-cr2" } - if bytes[0...3] == [0x49, 0x49, 0x2A, 0x00] || bytes[0...3] == [0x4D, 0x4D, 0x00, 0x2A] { + if data.count > 3, bytes[0...3] == [0x49, 0x49, 0x2A, 0x00] || bytes[0...3] == [0x4D, 0x4D, 0x00, 0x2A] { return "image/tiff" } - if bytes[0...1] == [0x42, 0x4D] { + if data.count > 1, bytes[0...1] == [0x42, 0x4D] { return "image/bmp" } - if bytes[0...3] == [0x50, 0x4B, 0x03, 0x04] && bytes[30...57] == [ + if data.count > 57, bytes[0...3] == [0x50, 0x4B, 0x03, 0x04] && bytes[30...57] == [ 0x6D, 0x69, 0x6D, 0x65, 0x74, 0x79, 0x70, 0x65, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x65, 0x70, 0x75, 0x62, 0x2B, 0x7A, 0x69, 0x70 @@ -77,35 +77,35 @@ func detectMimeType(for data: Data) -> String { return "application/epub+zip" } - if bytes[0...1] == [0x50, 0x4B] && (bytes[2] == 0x3 || bytes[2] == 0x5 || bytes[2] == 0x7) && (bytes[3] == 0x4 || bytes[3] == 0x6 || bytes[3] == 0x8) { + if data.count > 3, bytes[0...1] == [0x50, 0x4B] && (bytes[2] == 0x3 || bytes[2] == 0x5 || bytes[2] == 0x7) && (bytes[3] == 0x4 || bytes[3] == 0x6 || bytes[3] == 0x8) { return "application/zip" } - if bytes[257...261] == [0x75, 0x73, 0x74, 0x61, 0x72] { + if data.count > 261, bytes[257...261] == [0x75, 0x73, 0x74, 0x61, 0x72] { return "application/x-tar" } - if bytes[0...5] == [0x52, 0x61, 0x72, 0x21, 0x1A, 0x07] && (bytes[6] == 0x0 || bytes[6] == 0x1) { + if data.count > 6, bytes[0...5] == [0x52, 0x61, 0x72, 0x21, 0x1A, 0x07] && (bytes[6] == 0x0 || bytes[6] == 0x1) { return "application/x-rar-compressed" } - if bytes[0...2] == [0x1F, 0x8B, 0x08] { + if data.count > 2, bytes[0...2] == [0x1F, 0x8B, 0x08] { return "application/gzip" } - if bytes[0...2] == [0x42, 0x5A, 0x68] { + if data.count > 2, bytes[0...2] == [0x42, 0x5A, 0x68] { return "application/x-bzip2" } - if bytes[0...5] == [0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C] { + if data.count > 5, bytes[0...5] == [0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C] { return "application/x-7z-compressed" } - if bytes[0...1] == [0x78, 0x01] { + if data.count > 1, bytes[0...1] == [0x78, 0x01] { return "application/x-apple-diskimage" } - if (bytes[0...2] == [0x00, 0x00, 0x00] && (bytes[3] == 0x18 || bytes[3] == 0x20) && bytes[4...7] == [0x66, 0x74, 0x79, 0x70]) || + if data.count > 27, (bytes[0...2] == [0x00, 0x00, 0x00] && (bytes[3] == 0x18 || bytes[3] == 0x20) && bytes[4...7] == [0x66, 0x74, 0x79, 0x70]) || (bytes[0...3] == [0x33, 0x67, 0x70, 0x35]) || (bytes[0...11] == [0x00, 0x00, 0x00, 0x1C, 0x66, 0x74, 0x79, 0x70, 0x6D, 0x70, 0x34, 0x32] && bytes[16...27] == [0x6D, 0x70, 0x34, 0x31, 0x6D, 0x70, 0x34, 0x32, 0x69, 0x73, 0x6F, 0x6D]) || @@ -114,71 +114,71 @@ func detectMimeType(for data: Data) -> String { return "video/mp4" } - if bytes[0...10] == [0x00, 0x00, 0x00, 0x1C, 0x66, 0x74, 0x79, 0x70, 0x4D, 0x34, 0x56] { + if data.count > 10, bytes[0...10] == [0x00, 0x00, 0x00, 0x1C, 0x66, 0x74, 0x79, 0x70, 0x4D, 0x34, 0x56] { return "video/x-m4v" } - if bytes[0...7] == [0x00, 0x00, 0x00, 0x14, 0x66, 0x74, 0x79, 0x70] { + if data.count > 7, bytes[0...7] == [0x00, 0x00, 0x00, 0x14, 0x66, 0x74, 0x79, 0x70] { return "video/quicktime" } - if bytes[0...3] == [0x52, 0x49, 0x46, 0x46] && bytes[8...10] == [0x41, 0x56, 0x49] { + if data.count > 3, bytes[0...3] == [0x52, 0x49, 0x46, 0x46] && bytes[8...10] == [0x41, 0x56, 0x49] { return "video/x-msvideo" } - if bytes[0...9] == [0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9] { + if data.count > 9, bytes[0...9] == [0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9] { return "video/x-ms-wmv" } - if bytes[0...2] == [0x49, 0x44, 0x33] || bytes[0...1] == [0xFF, 0xFB] { + if data.count > 2, bytes[0...2] == [0x49, 0x44, 0x33] || bytes[0...1] == [0xFF, 0xFB] { return "audio/mpeg" } - if bytes[0...3] == [0x4D, 0x34, 0x41, 0x20] || bytes[4...10] == [0x66, 0x74, 0x79, 0x70, 0x4D, 0x34, 0x41] { + if data.count > 10, bytes[0...3] == [0x4D, 0x34, 0x41, 0x20] || bytes[4...10] == [0x66, 0x74, 0x79, 0x70, 0x4D, 0x34, 0x41] { return "audio/m4a" } - if bytes[28...35] == [0x4F, 0x70, 0x75, 0x73, 0x48, 0x65, 0x61, 0x64] { + if data.count > 35, bytes[28...35] == [0x4F, 0x70, 0x75, 0x73, 0x48, 0x65, 0x61, 0x64] { return "audio/opus" } - if bytes[0...3] == [0x4F, 0x67, 0x67, 0x53] { + if data.count > 3, bytes[0...3] == [0x4F, 0x67, 0x67, 0x53] { return "audio/ogg" } - if bytes[0...3] == [0x66, 0x4C, 0x61, 0x43] { + if data.count > 3, bytes[0...3] == [0x66, 0x4C, 0x61, 0x43] { return "audio/x-flac" } - if bytes[0...3] == [0x52, 0x49, 0x46, 0x46] && bytes[8...11] == [0x57, 0x41, 0x56, 0x45] { + if data.count > 3, bytes[0...3] == [0x52, 0x49, 0x46, 0x46] && bytes[8...11] == [0x57, 0x41, 0x56, 0x45] { return "audio/x-wav" } - if bytes[0...3] == [0x25, 0x50, 0x44, 0x46] { + if data.count > 3, bytes[0...3] == [0x25, 0x50, 0x44, 0x46] { return "application/pdf" } - if bytes[0...1] == [0x4D, 0x5A] { + if data.count > 1, bytes[0...1] == [0x4D, 0x5A] { return "application/x-msdownload" } - if bytes[0...4] == [0x7B, 0x5C, 0x72, 0x74, 0x66] { + if data.count > 4, bytes[0...4] == [0x7B, 0x5C, 0x72, 0x74, 0x66] { return "application/rtf" } - if bytes[0...4] == [0x00, 0x01, 0x00, 0x00, 0x00] { + if data.count > 4, bytes[0...4] == [0x00, 0x01, 0x00, 0x00, 0x00] { return "application/font-sfnt" } - if bytes[0...4] == [0x4F, 0x54, 0x54, 0x4F, 0x00] { + if data.count > 4, bytes[0...4] == [0x4F, 0x54, 0x54, 0x4F, 0x00] { return "application/font-sfnt" } - if bytes[0...7] == [0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1] { + if data.count > 7, bytes[0...7] == [0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1] { return "application/x-msi" } - if bytes[0] == 0x46 { + if data.count > 0, bytes[0] == 0x46 { return "text/plain" } diff --git a/Sources/Uploadcare/requestManager/RequestManager.swift b/Sources/Uploadcare/requestManager/RequestManager.swift index 1e0eb585..6712192e 100644 --- a/Sources/Uploadcare/requestManager/RequestManager.swift +++ b/Sources/Uploadcare/requestManager/RequestManager.swift @@ -34,7 +34,7 @@ internal class RequestManager { /// Library name private var libraryName = "UploadcareSwift" /// Library version - private var libraryVersion = "0.8.1" + private var libraryVersion = "0.8.2" /// API public key private var publicKey: String /// Secret Key. Optional. Is used for authorization diff --git a/Uploadcare.podspec b/Uploadcare.podspec index 4868bf65..57fe5417 100644 --- a/Uploadcare.podspec +++ b/Uploadcare.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Uploadcare' - s.version = '0.8.1' + s.version = '0.8.2' s.summary = 'Swift integration for Uploadcare' # This description is used to generate tags and improve search results.