diff --git a/Sources/FileType/Supported.swift b/Sources/FileType/Supported.swift index 165d902..5178aa8 100644 --- a/Sources/FileType/Supported.swift +++ b/Sources/FileType/Supported.swift @@ -1679,7 +1679,7 @@ public extension MimeType { return bytes[0...2] == [0x49, 0x49, 0xBC] }), .init(mime: "image/webp", type: .webp, bytesCount: 4, matches: { bytes, _ in - return bytes[8...11] == [0x57, 0x45, 0x42, 0x50] + return bytes.count > 7 && bytes[8...11] == [0x57, 0x45, 0x42, 0x50] }), .init(mime: "image/x-adobe-dng", type: .dng, bytesCount: 4, matches: { bytes, _ in // TODO: Implement magic number check for image/x-adobe-dng diff --git a/Tests/FileTypeTests/FileTypeTests.swift b/Tests/FileTypeTests/FileTypeTests.swift index e84257c..ab254b1 100644 --- a/Tests/FileTypeTests/FileTypeTests.swift +++ b/Tests/FileTypeTests/FileTypeTests.swift @@ -129,3 +129,8 @@ import Foundation } } +@Test func testBlankTxt() async throws { + let data = Data([0x33, 0x2E, 0x31, 0x30, 0x2E, 0x33, 0x0A]) // emty txt file bytes + #expect(FileType.mimeType(data: data) == nil) +} +