fold/tests/fixtures/swift/Sources/fuzz_me.swift
trvon 3ca6e0c176
feat: ObjC msgSend harness generator + Swift test fixture
- emitObjcHarness: objc_getClass + sel_registerName + objc_msgSend
  routes fuzzer bytes through ObjC dispatch instead of raw dlopen
- Swift fixture (tests/fixtures/swift/): 4 C-ABI functions,
  1 ObjC-exposed class with 3 methods, Swift-mangled symbols
- isSwiftMangled filter skips symbols needing object references
- Budget floor 30→120s, ceiling 120→600s (AFL++/libFuzzer norms)
2026-05-28 09:14:15 -04:00

51 lines
1.2 KiB
Swift

import Foundation
// ── C-ABI exports (safe for dlopen fuzzing) ──
@_cdecl("fuzz_c_add")
public func fuzz_c_add(_ a: UInt64, _ b: UInt64) -> UInt64 {
a &+ b
}
@_cdecl("fuzz_c_compare")
public func fuzz_c_compare(_ a: UInt64, _ b: UInt64) -> Int32 {
if a < b { return -1 }
if a > b { return 1 }
return 0
}
@_cdecl("fuzz_c_len")
public func fuzz_c_len(_ ptr: UnsafePointer<CChar>?) -> UInt64 {
guard let p = ptr else { return 0 }
var count: UInt64 = 0
while p[Int(count)] != 0 { count = count &+ 1 }
return count
}
@_cdecl("fuzz_c_memcpy")
public func fuzz_c_memcpy(_ dst: UnsafeMutablePointer<UInt8>?,
_ src: UnsafePointer<UInt8>?,
_ n: UInt64) -> UInt64 {
guard let d = dst, let s = src else { return 0 }
for i in 0..<min(n, 4096) {
d[Int(i)] = s[Int(i)]
}
return n
}
// ── ObjC-exposed class (routable via objc_msgSend) ──
@objc(FuzzMeClass)
public class FuzzMeClass: NSObject {
@objc public func add(_ a: Int, _ b: Int) -> Int {
a &+ b
}
@objc public func isEven(_ n: Int) -> Bool {
n % 2 == 0
}
@objc public func tokenize(_ input: String) -> [String] {
input.components(separatedBy: " ")
}
}