Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : security/tests/Sources/qyfuzz/main.swift8// Module : Tests9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0412// Last Modified : 2026-12-0413//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import AuditSupport42import Foundation43import FuzzTargets44import QyvoraMath4546// qyfuzz — fuzzing driver of the QYVORA security audit.47//48// qyfuzz list49// qyfuzz seed [--corpus DIR] [--target T]50// qyfuzz run --target T|all (--seconds N | --iterations N) [--slice S] [--seed S] [--workers W]51// [--corpus DIR] [--work DIR] [--crashes DIR] [--json FILE] [--timeout S]52// qyfuzz repro TARGET FILE53// qyfuzz minimize TARGET FILE [--out FILE]54// qyfuzz worker … (internal: one fuzz loop, started by `run`)55//56// `run` starts worker processes. A worker that dies (Swift trap, sanitizer report, invariant57// failure) or stops making progress is recorded with the input it was executing, then replaced.5859setvbuf(stdout, nil, _IOLBF, 0)6061struct Arguments {62 var positional = [String]()63 var options = [String: String]()6465 init(_ raw: [String]) {66 var i = 067 while i < raw.count {68 if raw[i].hasPrefix("--") {69 let key = String(raw[i].dropFirst(2))70 if i + 1 < raw.count, !raw[i + 1].hasPrefix("--") {71 options[key] = raw[i + 1]72 i += 273 } else {74 options[key] = "true"75 i += 176 }77 } else {78 positional.append(raw[i])79 i += 180 }81 }82 }8384 func string(_ key: String, _ fallback: String) -> String { options[key] ?? fallback }85 func double(_ key: String, _ fallback: Double) -> Double { options[key].flatMap(Double.init) ?? fallback }86 func int(_ key: String, _ fallback: Int) -> Int { options[key].flatMap(Int.init) ?? fallback }87 func url(_ key: String, _ fallback: URL) -> URL { options[key].map { URL(fileURLWithPath: $0) } ?? fallback }88}8990func fail(_ message: String) -> Never {91 FileHandle.standardError.write(Data(("qyfuzz: " + message + "\n").utf8))92 exit(2)93}9495let fuzzingRoot = AuditPaths.fuzzing96let defaultCorpus = fuzzingRoot.appendingPathComponent("corpus")97let defaultWork = fuzzingRoot.appendingPathComponent("work")98let defaultCrashes = fuzzingRoot.appendingPathComponent("crashes")99100func selectTargets(_ name: String) -> [FuzzTarget] {101 if name == "all" { return FuzzRegistry.all }102 let picked = name.split(separator: ",").compactMap { FuzzRegistry.target(String($0)) }103 if picked.isEmpty { fail("unknown target \(name); see `qyfuzz list`") }104 return picked105}106107func writeJSON(_ object: Any, to url: URL) {108 try? FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)109 if let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted, .sortedKeys]) { try? data.write(to: url) }110}111112// MARK: - Crash description113114struct CrashInfo {115 var kind: String // crash | hang116 var signal: Int32117 var exitCode: Int32118 var message: String // first meaningful line of stderr119 var site: String // deduplication key120 var stderrTail: String121}122123/// The line that says what happened, taken from the worker's stderr.124func describeCrash(stderr: String, signal: Int32, exitCode: Int32) -> (message: String, site: String) {125 let lines = stderr.split(separator: "\n").map(String.init)126 var message = ""127 for l in lines {128 if l.contains("FUZZ-INVARIANT") || l.contains("Fatal error") || l.contains("ERROR: AddressSanitizer") || l.contains("runtime error:")129 || l.contains("Precondition failed") || l.contains("Assertion failed") || l.contains("Unexpectedly found nil")130 {131 message = l132 break133 }134 }135 // first frame of the Swift backtrace that belongs to the engine or to a harness136 var frame = ""137 for l in lines where l.contains(" in ") && (l.contains("Qyvora") || l.contains("FuzzTargets")) && !l.contains("fuzzFail") {138 frame = l.trimmingCharacters(in: .whitespaces)139 if let r = frame.range(of: " in ") { frame = String(frame[r.upperBound...]) }140 break141 }142 if message.isEmpty { message = signal != 0 ? "terminated by signal \(signal)" : "exit code \(exitCode)" }143 var site = message144 if let r = site.range(of: "FUZZ-INVARIANT: ") { site = String(site[r.upperBound...]) }145 if !frame.isEmpty, !message.contains("FUZZ-INVARIANT") { site = frame + " | " + site }146 return (message, String(site.prefix(300)))147}148149/// Symbolicated frames of the crashed thread, from the report macOS writes for the worker150/// (`~/Library/Logs/DiagnosticReports/qyfuzz-*.ips`). A release build traps without a message, so this is151/// the only place that says where. Returns nil when no report for `pid` appears within `wait` seconds152/// (the system throttles reports of a process that crashes repeatedly).153func crashReportFrames(pid: Int32, since: Date, wait: Double = 5) -> [String]? {154 let dir = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Library/Logs/DiagnosticReports")155 let deadline = Date().addingTimeInterval(wait)156 repeat {157 let names = ((try? FileManager.default.contentsOfDirectory(atPath: dir.path)) ?? []).filter { $0.hasPrefix("qyfuzz") && $0.hasSuffix(".ips") }158 for name in names.sorted().reversed().prefix(40) {159 let url = dir.appendingPathComponent(name)160 guard let attributes = try? FileManager.default.attributesOfItem(atPath: url.path), let modified = attributes[.modificationDate] as? Date,161 modified >= since.addingTimeInterval(-2), let text = try? String(contentsOf: url, encoding: .utf8), let newline = text.firstIndex(of: "\n"),162 let body = try? JSONSerialization.jsonObject(with: Data(text[text.index(after: newline)...].utf8)) as? [String: Any],163 (body["pid"] as? Int).map({ Int32($0) }) == pid, let threads = body["threads"] as? [[String: Any]],164 let crashed = threads.first(where: { $0["triggered"] as? Bool == true }), let frames = crashed["frames"] as? [[String: Any]]165 else { continue }166 var out = [String]()167 for f in frames.prefix(24) {168 let symbol = f["symbol"] as? String ?? "?"169 if let file = f["sourceFile"] as? String, let line = f["sourceLine"] as? Int, !file.contains("compiler-generated") {170 out.append("\(file):\(line) \(symbol)")171 } else {172 out.append(symbol)173 }174 }175 return out176 }177 usleep(250_000)178 } while Date() < deadline179 return nil180}181182// MARK: - One worker process183184struct WorkerResult {185 var executions: UInt64 = 0186 var seconds = 0.0187 var added = 0188 var edges = 0189 var edgesTotal = 0190 var outcomeClasses = 0191 var coverageGuided = false192 var crash: CrashInfo?193 var crashInput = Bytes()194}195196final class Shared: @unchecked Sendable {197 let lock = NSLock()198 var next = 0199 var perTarget = [String: [String: Any]]()200 var crashes = [[String: Any]]()201 var crashSites = [String: Int]()202 var deadline = Date.distantFuture203204 func with<T>(_ body: (Shared) -> T) -> T {205 lock.lock()206 defer { lock.unlock() }207 return body(self)208 }209}210211func runWorker(executable: URL, target: FuzzTarget, seed: UInt64, seconds: Double, iterations: Int, corpus: URL, work: URL, slot: Int, timeout: Double) -> WorkerResult {212 let statusPath = work.appendingPathComponent("status-\(slot).bin").path213 let stderrPath = work.appendingPathComponent("stderr-\(slot).txt").path214 try? FileManager.default.removeItem(atPath: statusPath)215 FileManager.default.createFile(atPath: stderrPath, contents: nil)216 let p = Process()217 p.executableURL = executable218 p.arguments = [219 "worker", "--target", target.name, "--seed", String(seed), "--seconds", String(seconds), "--iterations", String(iterations),220 "--corpus", corpus.path, "--work", work.path, "--status", statusPath,221 ]222 var env = ProcessInfo.processInfo.environment223 env["ASAN_OPTIONS"] = (env["ASAN_OPTIONS"].map { $0 + ":" } ?? "") + "abort_on_error=1:detect_leaks=0:symbolize=1"224 env["QY_AUDIT_REPO"] = AuditPaths.repo.path225 p.environment = env226 let out = Pipe()227 p.standardOutput = out228 p.standardError = FileHandle(forWritingAtPath: stderrPath)229 p.standardInput = FileHandle.nullDevice230 var result = WorkerResult()231 let started = Date()232 do { try p.run() } catch {233 result.crash = CrashInfo(kind: "crash", signal: 0, exitCode: -1, message: "cannot start worker: \(error)", site: "worker start", stderrTail: "")234 return result235 }236 // progress watchdog: the worker bumps its execution counter in the status file237 var lastCount: UInt64 = 0238 var lastChange = Date()239 var hung = false240 nonisolated(unsafe) var output = Data()241 let reader = Thread { output = out.fileHandleForReading.readDataToEndOfFile() }242 reader.start()243 while p.isRunning {244 usleep(200_000)245 if let s = FuzzStatusFile.read(path: statusPath) {246 if s.executions != lastCount || s.phase == 3 {247 lastCount = s.executions248 lastChange = Date()249 }250 // phase 0/1: loading and first pass over the corpus (key generation for runtime seeds can be slow)251 let limit = s.phase < 2 ? max(timeout, 180) : timeout252 if Date().timeIntervalSince(lastChange) > limit {253 hung = true254 kill(p.processIdentifier, SIGKILL)255 break256 }257 } else if Date().timeIntervalSince(started) > max(timeout, 180) {258 hung = true259 kill(p.processIdentifier, SIGKILL)260 break261 }262 }263 p.waitUntilExit()264 while !reader.isFinished { usleep(1000) }265 result.seconds = Date().timeIntervalSince(started)266 let snapshot = FuzzStatusFile.read(path: statusPath)267 result.executions = snapshot?.executions ?? 0268 result.added = Int(snapshot?.added ?? 0)269 result.edges = Int(snapshot?.edges ?? 0)270 if let line = String(data: output, encoding: .utf8)?.split(separator: "\n").last(where: { $0.hasPrefix("{") }),271 let obj = try? JSONSerialization.jsonObject(with: Data(line.utf8)) as? [String: Any]272 {273 result.edgesTotal = obj["edges_total"] as? Int ?? 0274 result.outcomeClasses = obj["outcome_classes"] as? Int ?? 0275 result.coverageGuided = obj["coverage_guided"] as? Bool ?? false276 result.edges = obj["edges_covered"] as? Int ?? result.edges277 }278 let normal = p.terminationReason == .exit && p.terminationStatus == 0279 if hung || !normal {280 let text = (try? String(contentsOfFile: stderrPath, encoding: .utf8)) ?? ""281 let tail = String(text.suffix(6000))282 let signal: Int32 = p.terminationReason == .uncaughtSignal ? p.terminationStatus : 0283 let code: Int32 = p.terminationReason == .exit ? p.terminationStatus : 0284 var (message, site) = describeCrash(stderr: text, signal: signal, exitCode: code)285 var report = ""286 if hung {287 message = "no progress for \(Int(timeout)) s (hang or very slow input)"288 site = "hang"289 } else if !message.contains("FUZZ-INVARIANT"), let frames = crashReportFrames(pid: p.processIdentifier, since: started) {290 // where it trapped: the first frames that carry a source location291 let located = frames.filter { $0.contains(".swift:") && !$0.contains("fuzzFail") }292 let reason = frames.first { $0.hasPrefix("Swift runtime failure") } ?? message293 if let first = located.first {294 site = String(([first] + located.dropFirst().prefix(1)).joined(separator: " < ").prefix(300))295 message = "\(reason) at \(first)"296 }297 report = "\n--- crashed thread (macOS crash report) ---\n" + frames.joined(separator: "\n")298 }299 result.crash = CrashInfo(kind: hung ? "hang" : "crash", signal: signal, exitCode: code, message: message, site: site, stderrTail: tail + report)300 result.crashInput = snapshot?.input ?? []301 }302 return result303}304305// MARK: - Commands306307func commandList() {308 for t in FuzzRegistry.all {309 print("\(t.name.padding(toLength: 26, withPad: " ", startingAt: 0)) \(t.summary)")310 }311 print("\(FuzzRegistry.all.count) targets; coverage instrumentation in this build: \(FuzzCoverage.available ? "yes (\(FuzzCoverage.edgeCount) edges in \(FuzzCoverage.moduleCount) modules)" : "no")")312}313314func commandSeed(_ args: Arguments) {315 let corpus = args.url("corpus", defaultCorpus)316 var total = 0317 for t in selectTargets(args.string("target", "all")) {318 let dir = corpus.appendingPathComponent(t.name)319 var written = 0320 for s in FuzzRegistry.committedSeeds(t) {321 let url = dir.appendingPathComponent(FuzzFiles.name(s))322 if !FileManager.default.fileExists(atPath: url.path) { written += 1 }323 FuzzFiles.save(s, in: dir)324 }325 total += written326 print("\(t.name): \(FuzzFiles.load(dir).count) seed(s), \(written) new")327 }328 print("seeds written: \(total)")329}330331func commandWorker(_ args: Arguments) {332 let options = FuzzWorkerOptions(333 target: args.string("target", ""), seed: UInt64(args.string("seed", "1")) ?? 1, seconds: args.double("seconds", 0),334 iterations: UInt64(args.int("iterations", 0)), corpus: args.url("corpus", defaultCorpus), work: args.url("work", defaultWork),335 status: args.string("status", "/dev/null"))336 guard let summary = FuzzEngine.run(options) else { fail("worker could not start (unknown target or status file)") }337 if let data = try? JSONSerialization.data(withJSONObject: summary.json, options: [.sortedKeys]) { print(String(decoding: data, as: UTF8.self)) }338}339340func commandRepro(_ args: Arguments) {341 guard args.positional.count >= 2, let target = FuzzRegistry.target(args.positional[0]) else { fail("usage: qyfuzz repro TARGET FILE") }342 guard let data = FileManager.default.contents(atPath: args.positional[1]) else { fail("cannot read \(args.positional[1])") }343 // runtime seeds are part of the trusted set of an accept-only target344 let r = FuzzEngine.replay(target, Bytes(data))345 if target.acceptOnlySeeds, r.accepted {346 let trusted = Set(FuzzFiles.load(arguments.url("corpus", defaultCorpus).appendingPathComponent(target.name)).map(\.bytes))347 if !trusted.contains(Bytes(data)) { fuzzFail("\(target.name): an input that is not a committed valid seed was accepted") }348 }349 print("ok target=\(target.name) bytes=\(data.count) outcome=\(String(r.outcome, radix: 16)) accepted=\(r.accepted)")350}351352/// True when `input` still stops the harness (run in a child process).353func stillCrashes(_ executable: URL, _ target: String, _ input: Bytes, scratch: URL) -> Bool {354 try? Data(input).write(to: scratch)355 let p = Process()356 p.executableURL = executable357 p.arguments = ["repro", target, scratch.path]358 p.standardOutput = FileHandle.nullDevice359 p.standardError = FileHandle.nullDevice360 guard (try? p.run()) != nil else { return false }361 p.waitUntilExit()362 return !(p.terminationReason == .exit && p.terminationStatus == 0)363}364365func minimize(_ executable: URL, target: String, input: Bytes, scratch: URL, budget: Int = 1500) -> Bytes {366 var best = input367 var attempts = 0368 guard stillCrashes(executable, target, best, scratch: scratch) else { return input }369 var block = max(1, best.count / 2)370 while block >= 1, attempts < budget {371 var i = 0372 var progressed = false373 while i < best.count, attempts < budget {374 let end = min(best.count, i + block)375 let candidate = Bytes(best[0..<i]) + Bytes(best[end...])376 attempts += 1377 if !candidate.isEmpty, stillCrashes(executable, target, candidate, scratch: scratch) {378 best = candidate379 progressed = true380 } else {381 i += block382 }383 }384 if !progressed || block == 1 { block /= 2 }385 }386 // simplify the remaining bytes towards zero where it keeps the crash387 var k = 0388 while k < best.count, attempts < budget, best.count <= 256 {389 if best[k] != 0 {390 var candidate = best391 candidate[k] = 0392 attempts += 1393 if stillCrashes(executable, target, candidate, scratch: scratch) { best = candidate }394 }395 k += 1396 }397 return best398}399400func commandMinimize(_ args: Arguments, executable: URL) {401 guard args.positional.count >= 2, FuzzRegistry.target(args.positional[0]) != nil else { fail("usage: qyfuzz minimize TARGET FILE [--out FILE]") }402 guard let data = FileManager.default.contents(atPath: args.positional[1]) else { fail("cannot read \(args.positional[1])") }403 let scratch = FileManager.default.temporaryDirectory.appendingPathComponent("qyfuzz-min-\(getpid()).bin")404 defer { try? FileManager.default.removeItem(at: scratch) }405 let small = minimize(executable, target: args.positional[0], input: Bytes(data), scratch: scratch)406 let out = args.options["out"] ?? args.positional[1] + ".min"407 try? Data(small).write(to: URL(fileURLWithPath: out))408 print("minimised \(data.count) -> \(small.count) bytes: \(out)")409}410411func commandRun(_ args: Arguments, executable: URL) {412 let targets = selectTargets(args.string("target", "all"))413 let workers = max(1, args.int("workers", max(1, ProcessInfo.processInfo.activeProcessorCount / 2)))414 let seconds = args.double("seconds", 0)415 let iterations = args.int("iterations", 0)416 guard seconds > 0 || iterations > 0 else { fail("give --seconds N or --iterations N") }417 let corpus = args.url("corpus", defaultCorpus), work = args.url("work", defaultWork), crashes = args.url("crashes", defaultCrashes)418 let timeout = args.double("timeout", 30)419 let baseSeed = args.options["seed"].flatMap(UInt64.init) ?? AuditSeed.make("qyfuzz")420 try? FileManager.default.createDirectory(at: work, withIntermediateDirectories: true)421 // time mode: workers cycle through the targets in slices until the wall-clock budget is spent;422 // iteration mode: every target gets one worker run of N executions423 let slice = seconds > 0 ? args.double("slice", max(2, min(60, seconds * Double(workers) / Double(targets.count)))) : 0424 let shared = Shared()425 let started = Date()426 if seconds > 0 { shared.deadline = started.addingTimeInterval(seconds) }427 let maxSamplesPerSite = 3428 print("qyfuzz: \(targets.count) target(s), \(workers) worker(s), seed \(baseSeed), " + (seconds > 0 ? "\(Int(seconds)) s wall clock, slices of \(Int(slice)) s" : "\(iterations) iterations per target"))429430 let group = DispatchGroup()431 for slot in 0..<workers {432 group.enter()433 let thread = Thread {434 defer { group.leave() }435 while true {436 let job: (index: Int, target: FuzzTarget)? = shared.with { s in437 if seconds > 0 {438 guard Date() < s.deadline else { return nil }439 } else {440 guard s.next < targets.count else { return nil }441 }442 let i = s.next443 s.next += 1444 return (i, targets[i % targets.count])445 }446 guard let job else { break }447 let remaining = seconds > 0 ? shared.with { $0.deadline.timeIntervalSinceNow } : 0448 if seconds > 0, remaining < 0.5 { break }449 let seed = baseSeed &+ UInt64(job.index) &* 0x9e37_79b9_7f4a_7c15450 let r = runWorker(451 executable: executable, target: job.target, seed: seed, seconds: seconds > 0 ? min(slice, remaining) : 0, iterations: iterations,452 corpus: corpus, work: work, slot: slot, timeout: timeout)453 var savedCrash: URL?454 if let crash = r.crash {455 let key = job.target.name + " | " + crash.site456 let count = shared.with { s -> Int in457 s.crashSites[key, default: 0] += 1458 return s.crashSites[key] ?? 1459 }460 // without a located site, different defects share one key: keep more samples461 if count <= (crash.site.hasPrefix("terminated by signal") ? 12 : maxSamplesPerSite) {462 let dir = crashes.appendingPathComponent(job.target.name)463 let url = FuzzFiles.save(r.crashInput, in: dir, suffix: ".bin")464 let note = """465 target: \(job.target.name)466 kind: \(crash.kind)467 signal: \(crash.signal)468 exit: \(crash.exitCode)469 message: \(crash.message)470 site: \(crash.site)471 seed: \(seed)472 host: \(ProcessInfo.processInfo.hostName)473 input bytes: \(r.crashInput.count)474 input hex (first 512 bytes): \(Hex.encode(r.crashInput.prefix(512)))475476 --- stderr tail ---477 \(crash.stderrTail)478 """479 try? note.write(to: url.deletingPathExtension().appendingPathExtension("txt"), atomically: true, encoding: .utf8)480 savedCrash = url481 }482 print(" \(crash.kind.uppercased()) \(job.target.name): \(crash.message)")483 }484 shared.with { s in485 var t = s.perTarget[job.target.name] ?? [486 "target": job.target.name, "executions": 0, "seconds": 0.0, "crashes": 0, "hangs": 0, "runs": 0, "corpus_added": 0,487 "edges_covered": 0, "outcome_classes": 0,488 ]489 t["executions"] = (t["executions"] as? Int ?? 0) + Int(r.executions)490 t["seconds"] = (t["seconds"] as? Double ?? 0) + r.seconds491 t["runs"] = (t["runs"] as? Int ?? 0) + 1492 t["corpus_added"] = (t["corpus_added"] as? Int ?? 0) + r.added493 t["edges_covered"] = max(t["edges_covered"] as? Int ?? 0, r.edges)494 t["outcome_classes"] = max(t["outcome_classes"] as? Int ?? 0, r.outcomeClasses)495 if let crash = r.crash {496 t[crash.kind == "hang" ? "hangs" : "crashes"] = (t[crash.kind == "hang" ? "hangs" : "crashes"] as? Int ?? 0) + 1497 s.crashes.append([498 "target": job.target.name, "kind": crash.kind, "signal": Int(crash.signal), "exit": Int(crash.exitCode), "message": crash.message,499 "site": crash.site, "seed": String(seed), "file": savedCrash.map { $0.path } ?? "",500 "input_hex": Hex.encode(r.crashInput.prefix(2048)), "input_bytes": r.crashInput.count,501 ])502 }503 s.perTarget[job.target.name] = t504 }505 }506 }507 thread.stackSize = 1 << 20508 thread.start()509 }510 group.wait()511512 let wall = Date().timeIntervalSince(started)513 var rows = [[String: Any]]()514 var totalExec = 0, totalCrash = 0, totalHang = 0515 for t in targets {516 var row = shared.perTarget[t.name] ?? ["target": t.name, "executions": 0, "seconds": 0.0, "crashes": 0, "hangs": 0, "runs": 0]517 row["seconds"] = ((row["seconds"] as? Double ?? 0) * 100).rounded() / 100518 row["seed"] = String(baseSeed)519 row["corpus_size"] = FuzzFiles.load(corpus.appendingPathComponent(t.name)).count520 row["work_corpus_size"] = FuzzFiles.load(work.appendingPathComponent("corpus").appendingPathComponent(t.name), limit: 100_000).count521 totalExec += row["executions"] as? Int ?? 0522 totalCrash += row["crashes"] as? Int ?? 0523 totalHang += row["hangs"] as? Int ?? 0524 rows.append(row)525 }526 var sites = [[String: Any]]()527 for (k, v) in shared.crashSites.sorted(by: { $0.key < $1.key }) { sites.append(["site": k, "count": v]) }528 let summary: [String: Any] = [529 "tool": "qyfuzz", "coverage_guided": FuzzCoverage.available, "edges_instrumented": FuzzCoverage.edgeCount,530 "feedback": FuzzCoverage.available531 ? "edge coverage (LLVM SanitizerCoverage inline 8-bit counters, hit-count buckets) with our own mutation engine; not libFuzzer"532 : "none beyond outcome classes: mutation-based, NOT coverage-guided",533 "host": ProcessInfo.processInfo.hostName, "cores": ProcessInfo.processInfo.activeProcessorCount, "workers": workers, "seed": String(baseSeed),534 "started": ISO8601DateFormatter().string(from: started), "wall_seconds": (wall * 100).rounded() / 100,535 "mode": seconds > 0 ? "seconds" : "iterations", "budget": seconds > 0 ? seconds : Double(iterations), "targets": rows,536 "totals": ["executions": totalExec, "crashes": totalCrash, "hangs": totalHang, "targets": targets.count, "unique_crash_sites": shared.crashSites.count],537 "crashes": shared.crashes, "crash_sites": sites,538 ]539 if let path = args.options["json"] { writeJSON(summary, to: URL(fileURLWithPath: path)) }540 print("qyfuzz: \(totalExec) executions in \(Int(wall)) s over \(targets.count) target(s); crashes \(totalCrash) (\(shared.crashSites.count) distinct), hangs \(totalHang)")541 exit(totalCrash + totalHang > 0 ? 1 : 0)542}543544let raw = Array(CommandLine.arguments.dropFirst())545guard let command = raw.first else { fail("usage: qyfuzz list | seed | run | repro | minimize (see security/fuzzing/README.md)") }546let arguments = Arguments(Array(raw.dropFirst()))547let executable = URL(fileURLWithPath: Bundle.main.executablePath ?? CommandLine.arguments[0])548switch command {549case "list": commandList()550case "seed": commandSeed(arguments)551case "worker": commandWorker(arguments)552case "repro": commandRepro(arguments)553case "minimize": commandMinimize(arguments, executable: executable)554case "run": commandRun(arguments, executable: executable)555default: fail("unknown command \(command)")556}557