fix(amp): clamp cab selector before Int() in isCabinetBypassed
External-review blocker: a huge finite cab value (from a corrupted or hand-edited rig JSON, restored unclamped via PedalState.selectorValues) would trap Int(cab.rounded()) at board-build time. Clamp in Double space first, mirroring CabinetVoice.voice(atSelectorValue:). Regression test renders infinity / ±1e20 / NaN / out-of-range cab values without trapping. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -350,7 +350,10 @@ open class AmpVoicePedal: Pedal {
|
||||
/// > low-pass) — expected; a cabinet is what tames the top end.
|
||||
var isCabinetBypassed: Bool {
|
||||
guard cab.isFinite else { return false }
|
||||
return Int(cab.rounded()) >= CabinetVoice.allCases.count
|
||||
// Clamp in Double space before converting: a huge finite `cab` (from a corrupted/hand-edited
|
||||
// rig) would otherwise trap `Int(_:)` — same defense as `CabinetVoice.voice(atSelectorValue:)`.
|
||||
let bounded: Double = Swift.min(Swift.max(cab, 0.0), Double(CabinetVoice.allCases.count))
|
||||
return Int(bounded.rounded()) >= CabinetVoice.allCases.count
|
||||
}
|
||||
|
||||
/// The per-channel cabinet + output stage: cabinet convolver (or a straight pass at the "None"
|
||||
|
||||
@@ -285,6 +285,16 @@ struct AmpVoicePedalTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test func extremeCabValuesDoNotTrap() throws {
|
||||
// A corrupted/hand-edited rig can restore any Double into `cab`. Neither the bypass check nor
|
||||
// the voice lookup may trap `Int(_:)` — every value must resolve to a defined, finite render.
|
||||
let extremes: [Double] = [.infinity, -.infinity, 1.0e20, -1.0e20, .nan, 999.0]
|
||||
for cabValue: Double in extremes {
|
||||
let out: [Float] = try render({ CaliforniaAmpPedal() }) { $0.cab = cabValue }
|
||||
#expect(out.allSatisfy { $0.isFinite }, "cab=\(cabValue) produced non-finite output")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func cabSelectorExposesNoneStop() throws {
|
||||
let stops: [PedalSelectorKnob.Stop] = CaliforniaAmpPedal().effectSelectors
|
||||
.first { $0.label == "Cab" }?.stops ?? []
|
||||
|
||||
Reference in New Issue
Block a user