From f0f8f7f4faafbc5dcdd682dc36d349b1993a4bbf Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 10:00:38 +0700 Subject: [PATCH] M4: enforce global native FX lease token uniqueness before PCM publication --- engine/core/DynamicChannelFxLeaseBank.h | 12 ++++++++++-- tests/live_channel_fx_graph_test.cpp | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/engine/core/DynamicChannelFxLeaseBank.h b/engine/core/DynamicChannelFxLeaseBank.h index b94e7dc6c..ee47cdb40 100644 --- a/engine/core/DynamicChannelFxLeaseBank.h +++ b/engine/core/DynamicChannelFxLeaseBank.h @@ -125,12 +125,20 @@ class DynamicChannelFxLeaseBank final { owner->latencySamples>armix::dsp::StereoLatencyDelay::maximumSamples || owner->latencyChanged.load(std::memory_order_acquire)) return Fault::uncompensatedLatency; + // A cloned/restored processor may have a different pointer + // but reuse another plugin's durable instance token. Reject it + // BEFORE publishing a graph: FX MOVE, bypass, editor and + // .smix restoration all identify leases by this opaque token. + // This comparison and all JUCE strings stay on CONTROL only. + if(owner->instanceId.isEmpty())return Fault::emptyLease; for(const auto& existing:candidate.rows_) for(std::size_t k=0;kinstanceId==owner->instanceId) return Fault::duplicateInstance; for(std::size_t k=0;kinstanceId==owner->instanceId) return Fault::duplicateInstance; row.owners[i]=owner; // owner reference acquired OFF realtime row.raw[i]=owner.get(); diff --git a/tests/live_channel_fx_graph_test.cpp b/tests/live_channel_fx_graph_test.cpp index f14648434..bed90b133 100644 --- a/tests/live_channel_fx_graph_test.cpp +++ b/tests/live_channel_fx_graph_test.cpp @@ -218,6 +218,25 @@ static void verifyUniversalChannelIdFxLeaseAndLivePcm() { alias[1].inserts=first.inserts; // same native processor twice assert(Bank::prepare(epoch,2,alias,blocked)==Bank::Fault::duplicateInstance); assert(blocked.lanes()==0); + // Distinct native processors can still carry the SAME restored instance + // identity. Pointer-only guards miss this and allow the UI/editor to + // confuse two owners even if the accepted snapshot later rejects them. + auto collidingProcessor=std::make_unique(1.125f); + collidingProcessor->prepareToPlay(48000.,64); + const auto restoredId=first.inserts[0]->instanceId; + auto sameTokenDifferentOwner=std::make_shared( + std::move(collidingProcessor),"collision-fixture","Collision fixture",64, + restoredId); + assert(sameTokenDifferentOwner.get()!=first.inserts[0].get()); + alias[1].inserts={sameTokenDifferentOwner}; + assert(Bank::prepare(epoch,2,alias,blocked)==Bank::Fault::duplicateInstance); + assert(blocked.lanes()==0); + Bank::Assignment sameChannel=first; + sameChannel.inserts.push_back(sameTokenDifferentOwner); + assert(Bank::prepare(epoch,2,std::span(&sameChannel,1),blocked)== + Bank::Fault::duplicateInstance); + assert(blocked.lanes()==0 && bank.insertCount(ch1)==1 && + bank.insertCount(ch11)==1); // previous accepted graph untouched // A fixed-latency VST lease is admitted; the PCM publisher consumes its // exact inventory to prepare fan-in compensation before publication. auto latentProcessor=std::make_unique(1.5f);