Skip to content
Merged
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
10 changes: 7 additions & 3 deletions Tests/CoreRasterTests/JPEGReadGuardTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ import Foundation
@Test func shortScanNamed() {
let f = F.Frame(width: 8, height: 8, block: F.seeded(0))
let two = F.Huffman(bits: [2] + [Int](repeating: 0, count: 15), values: [0, 0])
let sof = F.segment(0xC0, [8] + F.be16(8) + F.be16(8) + [1, 1, 0x11, 0])
let head = [0xFF, 0xD8] + F.dqt(0, f.tables[0]) + sof + F.dht(0, 0, two) + F.dht(1, 0, two)
let text = damagedText { try JPEG.read(Data(head + F.sos([0], 0, 63, 0, 0) + [0xFF, 0xD9])) }
// Built as lists of parts: one long `+` chain times out the macOS type checker.
let frame: [[UInt8]] = [[8], F.be16(8), F.be16(8), [1, 1, 0x11, 0]]
let sof = F.segment(0xC0, Array(frame.joined()))
let parts: [[UInt8]] = [[0xFF, 0xD8], F.dqt(0, f.tables[0]), sof, F.dht(0, 0, two), F.dht(1, 0, two),
F.sos([0], 0, 63, 0, 0), [0xFF, 0xD9]]
let data = Data(Array(parts.joined()))
let text = damagedText { try JPEG.read(data) }
#expect(text?.contains("scan ends at MCU 0") == true, "\(text ?? "no damaged")")
}

Expand Down
4 changes: 3 additions & 1 deletion Tests/CoreRasterTests/JPEGReadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ import Foundation
let dcScan = coded({ $0.put(dc, 3); $0.put(7, 3) }, { $0.put(dc, 3); $0.put(2, 3) })
let acScan = coded({ $0.put(ac, 0x10); $0.put(0, 1) }, { $0.put(ac, 0x02); $0.put(3, 2); $0.put(ac, 0x00) })
let head = F.header(f, sof: 0xC2, precision: 8, restart: 1, orientation: nil, littleEndian: false, ac: (F.acAll, F.acAll))
let data = Data(head + F.sos([0], 0, 0, 0, 0) + dcScan + F.sos([0], 1, 63, 0, 0) + acScan + [0xFF, 0xD9])
// Built as a list of parts: one long `+` chain times out the macOS type checker.
let parts: [[UInt8]] = [head, F.sos([0], 0, 0, 0, 0), dcScan, F.sos([0], 1, 63, 0, 0), acScan, [0xFF, 0xD9]]
let data = Data(Array(parts.joined()))
#expect(try JPEG.read(data) == JPEG.read(F.baseline(f)))
}

Expand Down
Loading