From e1d541bded2a4ba371019a2d395e5d02f45f9654 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 13:38:24 +0700 Subject: [PATCH 1/2] M2/M3: fail-closed device name types and sustained native render evidence windows --- .../M3_RENDER_PATH_EVIDENCE_20261111.md | 23 +++++++ engine/core/ProductionRenderAudit.h | 63 +++++++++++++++++++ src/NativeDeviceApplyCoordinator.h | 17 ++++- .../native_device_apply_coordinator_test.cpp | 14 ++++- tests/production_render_audit_test.cpp | 60 ++++++++++++++++++ 5 files changed, 173 insertions(+), 4 deletions(-) diff --git a/docs/architecture/M3_RENDER_PATH_EVIDENCE_20261111.md b/docs/architecture/M3_RENDER_PATH_EVIDENCE_20261111.md index e16a1bef4..07c01ba76 100644 --- a/docs/architecture/M3_RENDER_PATH_EVIDENCE_20261111.md +++ b/docs/architecture/M3_RENDER_PATH_EVIDENCE_20261111.md @@ -54,3 +54,26 @@ The native audit header now exposes `ProductionRenderAudit::assessWindow(before, The result `exclusiveNativeObserved` requires at least one **completed** native callback in the bounded window, zero newly rendered M4 blocks, zero native failures or overlap denials, and zero unpatched/muted-no-render exits. It rejects process/device epoch discontinuity, counter regression/reset, and unsettled endpoint snapshots (which can occur because the source counters are independent relaxed atomics). An M4 total from a *previous* window does not itself disqualify current native-only evidence; an M4 increment **in** the window always does. This deliberately does **not** authorize audio, promise audible ASIO, qualify a device, or automatically remove the compatibility code. A single clean window is insufficient for M3b retirement. Repeat across real hardware sessions and record the matching output identity, source-only and WIRE/BUS/FX PCM fixtures, muted/not-muted state, sample rate/buffer transitions, and independent headphone listening. Until then M4 remains reachable. No new renderer, UI polling, or heavy workflow is introduced. + + +## M3c: bounded multi-window evidence (CONTROL only) + +`ProductionRenderAudit::assessSeries(boundaries,minimumNativeCompleted)` +requires at least **three consecutive clean bounded render windows** and a +nonzero native callback coverage threshold (default 128 completed callbacks). +Every boundary must supply independently verified **same process nonce, +same physical device epoch and installed ChannelId admission**. It rejects +M4 activity, partial/in-flight counters, native failures, overlap denials, +unpatched or muted-no-render activity, device epochs changing midseries, +counter regression and too little callback coverage. A historical M4 count +before the first boundary does not contaminate a later clean series. + +This is a read-only, allocation-free CONTROL-side evidence helper with +deterministic native tests; it does **not** automatically read hardware facts, +grant audio permission, delete legacy M4 code or prove physical ASIO output. +Field runs must collect genuine `dryRoutingLab.renderAudit` snapshots and +independently record exact device+pins and installed graph evidence. Qualify +distinct post-restart/device configurations in separate consecutive series. +Legacy M4 code must remain until separate *physical* FAT and full WIRE/BUS/FX +PCM continuity is witnessed. A clean CI test of the classifier does not +qualify any real interface or vendor plugin. diff --git a/engine/core/ProductionRenderAudit.h b/engine/core/ProductionRenderAudit.h index 8cd098811..821ad3f45 100644 --- a/engine/core/ProductionRenderAudit.h +++ b/engine/core/ProductionRenderAudit.h @@ -2,6 +2,8 @@ #pragma once #include #include +#include +#include // Read-only evidence for the single JUCE production renderer. Neither this // type nor its counters authorize PCM/output. No heap, lock, wait or log on RT. @@ -78,6 +80,67 @@ class ProductionRenderAudit final { return {WindowStatus::silentOrMuted,delta}; return {WindowStatus::exclusiveNativeObserved,delta}; } + // CONTROL-only, conservative evidence over MULTIPLE nonempty bounded + // windows. This prevents one short transient native window from being + // mistaken for proof that the M4 compatibility path can be retired. + // processNonce/epoch/admission must come from independently checked + // device/session evidence, not from a browser badge or raw counter. + // A continuous span crosses NO device restarts; repeat on a new epoch. + struct Boundary { + Snapshot counters{}; + std::uint64_t processNonce=0,deviceEpoch=0; + bool verifiedInstalledChannelId=false; + }; + enum class SeriesStatus : std::uint8_t { + tooFewWindows,invalidContext,badRenderWindow, + insufficientNativeBlocks,continuousNativeObserved + }; + struct RenderSeries { + SeriesStatus status=SeriesStatus::tooFewWindows; + WindowStatus firstBadWindow=WindowStatus::invalidContext; + std::uint64_t nativeCompleted=0; + [[nodiscard]] constexpr bool continuousNativeObserved() const noexcept { + return status==SeriesStatus::continuousNativeObserved; + } + }; + [[nodiscard]] static constexpr RenderSeries assessSeries( + std::span boundaries, + std::uint64_t minimumNativeCompleted=128) noexcept { + // Require >=3 independent bounded windows, not a single callback. + // A zero caller-selected threshold cannot bypass the evidence gate. + if(boundaries.size()<4 || minimumNativeCompleted==0) + return {SeriesStatus::tooFewWindows,WindowStatus::invalidContext,0}; + const auto& first=boundaries.front(); + if(!first.processNonce || !first.deviceEpoch || + !first.verifiedInstalledChannelId) + return {SeriesStatus::invalidContext,WindowStatus::invalidContext,0}; + std::uint64_t total=0; + for(std::size_t i=1;istd::numeric_limits::max()- + window.delta.nativeCompleted) + return {SeriesStatus::badRenderWindow, + WindowStatus::countersRegressed,total}; + total+=window.delta.nativeCompleted; + } + return total>=minimumNativeCompleted? + RenderSeries{SeriesStatus::continuousNativeObserved, + WindowStatus::exclusiveNativeObserved,total}: + RenderSeries{SeriesStatus::insufficientNativeBlocks, + WindowStatus::noNativeRender,total}; + } ProductionRenderAudit()=default; ProductionRenderAudit(const ProductionRenderAudit&)=delete; ProductionRenderAudit& operator=(const ProductionRenderAudit&)=delete; diff --git a/src/NativeDeviceApplyCoordinator.h b/src/NativeDeviceApplyCoordinator.h index 31dceba31..404050d22 100644 --- a/src/NativeDeviceApplyCoordinator.h +++ b/src/NativeDeviceApplyCoordinator.h @@ -58,9 +58,20 @@ class NativeDeviceApplyCoordinator final { return out; } auto& r=out.value; - r.backend=config.getProperty("backend",{}).toString(); - r.capture=config.getProperty("captureDevice",{}).toString(); - r.playback=config.getProperty("playbackDevice",{}).toString(); + const auto rawBackend=config.getProperty("backend",{}); + const auto rawCapture=config.getProperty("captureDevice",{}); + const auto rawPlayback=config.getProperty("playbackDevice",{}); + // Device names are exact JUCE-provided strings. A JSON number, + // boolean or object must never be string-coerced into a physical + // endpoint. An omitted/empty capture is valid for output-only mode. + if(!rawBackend.isString() || !rawPlayback.isString() || + (!rawCapture.isVoid() && !rawCapture.isString())) { + out.error="Invalid audio device name types"; + return out; + } + r.backend=rawBackend.toString(); + r.capture=rawCapture.isVoid()?juce::String{}:rawCapture.toString(); + r.playback=rawPlayback.toString(); if(r.backend.isEmpty()||r.playback.isEmpty()|| r.backend.length()>160||r.capture.length()>250||r.playback.length()>250) { out.error="Choose an actual playback device"; diff --git a/tests/native_device_apply_coordinator_test.cpp b/tests/native_device_apply_coordinator_test.cpp index 76e47afe6..d41f50a7f 100644 --- a/tests/native_device_apply_coordinator_test.cpp +++ b/tests/native_device_apply_coordinator_test.cpp @@ -80,10 +80,22 @@ int main() { "sampleRate":0,"bufferSize":0})"); auto output=Coordinator::parse(outputOnly); assert(output && output.value.rate==0. && output.value.block==0.); + // Capture name is optional only when it is genuinely absent or empty. + const auto explicitEmpty=config(R"({"backend":"Windows Audio", + "captureDevice":"","playbackDevice":"Speakers","sampleRate":0,"bufferSize":0})"); + const auto outputParsed=Coordinator::parse(explicitEmpty); + assert(outputParsed && outputParsed.value.capture.isEmpty()); assert(Coordinator::validateNames(output.value,{},{"Speakers"},true).isEmpty()); assert(Coordinator::validateNames(output.value,{},{"Speakers"},false).isNotEmpty()); for(const auto& invalid : { - "{}", R"({"backend":"ASIO","playbackDevice":"X","sampleRate":"48000","bufferSize":256})", + "{}", R"({"backend":42,"playbackDevice":"X","sampleRate":48000,"bufferSize":256})", + R"({"backend":true,"playbackDevice":"X","sampleRate":48000,"bufferSize":256})", + R"({"backend":"ASIO","playbackDevice":19,"sampleRate":48000,"bufferSize":256})", + R"({"backend":"ASIO","playbackDevice":true,"sampleRate":48000,"bufferSize":256})", + R"({"backend":"ASIO","captureDevice":false,"playbackDevice":"X","sampleRate":48000,"bufferSize":256})", + R"({"backend":"ASIO","captureDevice":72,"playbackDevice":"X","sampleRate":48000,"bufferSize":256})", + R"({"backend":"ASIO","playbackDevice":["X"],"sampleRate":48000,"bufferSize":256})", + R"({"backend":"ASIO","playbackDevice":"X","sampleRate":"48000","bufferSize":256})", R"({"backend":"ASIO","playbackDevice":"X","sampleRate":4000,"bufferSize":256})", R"({"backend":"ASIO","playbackDevice":"X","sampleRate":48000,"bufferSize":1.5})", R"({"backend":"ASIO","playbackDevice":"X","sampleRate":48000,"bufferSize":8193})", diff --git a/tests/production_render_audit_test.cpp b/tests/production_render_audit_test.cpp index d1759b4d1..83472245d 100644 --- a/tests/production_render_audit_test.cpp +++ b/tests/production_render_audit_test.cpp @@ -3,6 +3,7 @@ #undef NDEBUG #endif #include "../engine/core/ProductionRenderAudit.h" +#include #include #include #include @@ -90,6 +91,65 @@ int main() { assert(Audit::assessWindow(begin,withUnpatched,true,true,true).status== Status::silentOrMuted); + // M3c: a single successful render window cannot qualify sustained + // native-only ownership. Every boundary needs independent same-process + // same-physical-epoch admission, and each intervening window must prove + // completed ChannelId PCM with no M4/silent/failed/overlap activity. + using Boundary=Audit::Boundary; + using SeriesStatus=Audit::SeriesStatus; + Audit continuous; + continuous.started(Audit::Path::compatibilityM4); + continuous.completed(Audit::Path::compatibilityM4); // historical only + std::array boundaries{}; + for(std::size_t i=0;i{ + boundaries.data(),3},1).status==SeriesStatus::tooFewWindows); + auto stale=boundaries; + stale[2].deviceEpoch=20; + assert(Audit::assessSeries(stale,1).status==SeriesStatus::invalidContext); + stale=boundaries; + stale[1].processNonce=74; + assert(Audit::assessSeries(stale,1).status==SeriesStatus::invalidContext); + stale=boundaries; + stale[2].verifiedInstalledChannelId=false; + assert(Audit::assessSeries(stale,1).status==SeriesStatus::invalidContext); + stale=boundaries; + stale[0].processNonce=0; + assert(Audit::assessSeries(stale,1).status==SeriesStatus::invalidContext); + stale=boundaries; + ++stale[2].counters.m4Started; + ++stale[2].counters.m4Completed; + const auto legacyInWindow=Audit::assessSeries(stale,1); + assert(legacyInWindow.status==SeriesStatus::badRenderWindow); + assert(legacyInWindow.firstBadWindow==Status::legacyRendered); + stale=boundaries; + ++stale[2].counters.mutedNoRender; + assert(Audit::assessSeries(stale,1).status==SeriesStatus::badRenderWindow); + stale=boundaries; + ++stale[2].counters.nativeStarted; // genuine in-flight snapshot + assert(Audit::assessSeries(stale,1).status==SeriesStatus::badRenderWindow); + stale=boundaries; + stale[2].counters.nativeStarted=0; // reset or swapped process + const auto resetSeries=Audit::assessSeries(stale,1); + assert(resetSeries.status==SeriesStatus::badRenderWindow); + assert(resetSeries.firstBadWindow==Status::countersRegressed); + // These results never authorize output, retire M4 or replace physical + // ASIO field evidence. A different epoch requires a NEW series. + // A clean native window is *render ownership evidence only*. Neither // this test nor the classifier is an audible ASIO physical FAT. } From 4497119e2fd03fa5c1b2f3f30eb8ba8a240cc75e Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 13:47:44 +0700 Subject: [PATCH 2/2] M4: reject malformed built-in FX device format before processor construction --- src/NativeBuiltInFx.h | 12 +++++++++- tests/native_fx_registry_extension_test.cpp | 25 ++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/NativeBuiltInFx.h b/src/NativeBuiltInFx.h index 11cf3d1c5..a2c1a8092 100644 --- a/src/NativeBuiltInFx.h +++ b/src/NativeBuiltInFx.h @@ -5,7 +5,9 @@ #include "../engine/builtin_fx/ChannelCompressorProcessor.h" #include "../engine/builtin_fx/ChannelHarmonyProcessor.h" #include "../engine/builtin_fx/VocalThrowProcessor.h" +#include "../engine/core/PreparedMixerBlock.h" #include +#include #include #include #include @@ -35,7 +37,15 @@ std::unique_ptr prepareNativeBuiltInFx( double rate,int frames,const void* state,int bytes) { // State bytes are CONTROL-only. A missing pointer with a positive size // must never be mistaken for a valid default, especially during restore. - if(bytes<0 || bytes>8*1024*1024 || + // Reject malformed device formats BEFORE constructing any DSP/hosted + // processor. This is shared by EQ, Compressor, Harmonice, Vocal Throw, + // offline .smix restore and future built-in catalog entries. A corrupt + // rate/quantum must not cause extreme allocation inside prepareToPlay. + // 16-frame ASIO is deliberately valid at the universal host boundary; + // a processor may impose stricter limits via its own isReady() policy. + if(!std::isfinite(rate) || rate<8000. || rate>384000. || + frames<16 || frames>armix::mixer::PreparedMixerBlock::hardFrameLimit || + bytes<0 || bytes>8*1024*1024 || (state==nullptr && bytes!=0) || (state!=nullptr && bytes==0)) return {}; auto processor=std::make_unique(); diff --git a/tests/native_fx_registry_extension_test.cpp b/tests/native_fx_registry_extension_test.cpp index 21ac5e291..84cb7a3a3 100644 --- a/tests/native_fx_registry_extension_test.cpp +++ b/tests/native_fx_registry_extension_test.cpp @@ -15,9 +15,10 @@ // new branches in Main, the route graph, WebView or the JUCE callback. class FixtureGainFx final : public juce::AudioProcessor { public: + inline static int constructed=0; // CONTROL-only fixture FixtureGainFx():juce::AudioProcessor(BusesProperties() .withInput("Main",juce::AudioChannelSet::stereo(),true) - .withOutput("Main",juce::AudioChannelSet::stereo(),true)){} + .withOutput("Main",juce::AudioChannelSet::stereo(),true)){++constructed;} const juce::String getName() const override {return "Fixture Gain";} void prepareToPlay(double rate,int frames) override { ready_=(rate>=8000. && frames>=32); @@ -165,6 +166,28 @@ int main() { assert(armix::builtin_fx::findNativeBuiltInFx(production.id)==&production); constexpr float gain=1.5f; + // M4: malformed device rate/quantum must fail before even creating a + // processor. This prevents huge DSP buffers or bad fractional clocks + // from a corrupted saved Show/driver request. + const int beforeInvalid=FixtureGainFx::constructed; + for(const double rate:{ + std::numeric_limits::quiet_NaN(), + std::numeric_limits::infinity(), + -std::numeric_limits::infinity(), + 0.,7999.,384001.}) { + assert(!found->prepare(rate,128,&gain,sizeof(gain))); + } + for(int frames:{-1,0,1,15,8193,std::numeric_limits::max()}) { + assert(!found->prepare(48000.,frames,&gain,sizeof(gain))); + } + assert(!found->prepare(48000.,128,nullptr,1)); + assert(!found->prepare(48000.,128,&gain,-1)); + assert(!found->prepare(48000.,128,&gain,8*1024*1024+1)); + assert(FixtureGainFx::constructed==beforeInvalid); + // Host accepts the minimum legitimate 16-frame boundary. The fixture + // itself deliberately asks for >=32 and may reject after construction. + assert(!found->prepare(48000.,16,&gain,sizeof(gain))); + assert(FixtureGainFx::constructed==beforeInvalid+1); auto prepared=found->prepare(48000.,128,&gain,sizeof(gain)); assert(prepared!=nullptr); assert(prepared->getLatencySamples()==0);