Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/NFCPassportReader/DataGroups/DataGroup2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ public class DataGroup2 : DataGroup {

func parseISO19794_5( data : [UInt8] ) throws {
// Validate header - 'F', 'A' 'C' 0x00 - 0x46414300
if data[0] != 0x46 && data[1] != 0x41 && data[2] != 0x43 && data[3] != 0x00 {
guard data.count >= 4 else {
throw NFCPassportReaderError.UnknownImageFormat
}
if data[0] != 0x46 || data[1] != 0x41 || data[2] != 0x43 || data[3] != 0x00 {
throw NFCPassportReaderError.InvalidResponse(
dataGroupId: datagroupType,
expectedTag: 0x46,
Expand Down
8 changes: 8 additions & 0 deletions Tests/NFCPassportReaderTests/DataGroupParsingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ final class DataGroupParsingTests: XCTestCase {
}

}

func testDatagroup2RejectsInvalidFACHeader() {
// Same truncated DG2 as JPEG2000, but FAC trailer 0x00 replaced with 0x01.
// The old `&&` header check only rejected when every byte was wrong.
let dg2 = hexRepToBin("75617F61570201017F6082203FA1128002010081010282010087020101880200085F2E38464143013031300000002026000100002018000000000000000000010000000000000001000000000000000000000000000C6A5020200D0A")
let dgp = DataGroupParser()
XCTAssertThrowsError(try dgp.parseDG(data: dg2))
}

func testDatagroup2ParsingJPEG() {

Expand Down