Skip to content

Commit 64b123f

Browse files
authored
M6: fail-closed native FX lease uniqueness in approved projection (#562)
* guard(m6): reject duplicate FX instance leases and overfull native projection racks * test(m6): native projection rejects duplicate vendor FX leases and overfull racks mutation-free
1 parent 577c00b commit 64b123f

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

‎integration/ApprovedNativeV8Projection.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ inline bool projectNativeGraph(juce::var& snapshot,const juce::var& bus,
4646
if(!rows||rows->isEmpty()||!edges||!nativeV8Decimal(rev)||
4747
!nativeV8Decimal(roster))return false;
4848
juce::Array<juce::var> channels,wires,destinations;
49-
std::unordered_set<std::string> ids,edgeIds;
49+
std::unordered_set<std::string> ids,edgeIds,fxInstanceTokens;
5050
auto meters=std::make_unique<juce::DynamicObject>();
5151
juce::String mainId;
5252
for(const auto& row:*rows) {
@@ -64,7 +64,8 @@ inline bool projectNativeGraph(juce::var& snapshot,const juce::var& bus,
6464
(format!="MONO"&&format!="STEREO")||
6565
!out.isString()||!nativeV8Number(fader,linear)||
6666
!nativeV8Number(pan,p)||linear<0.||linear>4.||p< -1.||p>1.||
67-
!mute.isBool()||!solo.isBool()||!inserts.isArray())return false;
67+
!mute.isBool()||!solo.isBool()||!inserts.isArray()||
68+
inserts.getArray()->size()>8)return false;
6869
if(role=="MAIN"){if(mainId.isNotEmpty())return false;mainId=id.toString();}
6970
auto ch=std::make_unique<juce::DynamicObject>();
7071
ch->setProperty("id",id);ch->setProperty("name",name);
@@ -93,7 +94,9 @@ inline bool projectNativeGraph(juce::var& snapshot,const juce::var& bus,
9394
if(!token.isString()||token.toString().isEmpty()||
9495
!catalog.isString()||catalog.toString().isEmpty()||
9596
catalog.toString().getNumBytesAsUTF8()>256||
96-
!label.isString()||!bypass.isBool())return false;
97+
!label.isString()||!bypass.isBool()||
98+
!fxInstanceTokens.insert(token.toString().toStdString()).second)
99+
return false;
97100
auto insert=std::make_unique<juce::DynamicObject>();
98101
insert->setProperty("id",token);insert->setProperty("catalogId",catalog);
99102
insert->setProperty("name",label);

‎tests/approved_native_v8_projection_test.cpp‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,46 @@ static void nativeInsertCatalogInstanceProjectionRegression() {
114114
const auto before=juce::JSON::toString(untouched,false);
115115
assert(!projectApprovedNativeV8(untouched,invalid,true));
116116
assert(juce::JSON::toString(untouched,false)==before);
117+
118+
// M6: the native projection is the first fail-closed boundary for
119+
// unstable VST3 lease tokens. JS must never be asked to guess which
120+
// physical plugin/editor is owned by a duplicated instance identity.
121+
const auto rejectUnchanged=[](const juce::var& bus) {
122+
auto untouched=canonicalSnapshot();
123+
const auto before=juce::JSON::toString(untouched,false);
124+
assert(!projectApprovedNativeV8(untouched,bus,true));
125+
assert(juce::JSON::toString(untouched,false)==before);
126+
};
127+
auto duplicateAcrossChannels=juce::JSON::parse(
128+
juce::JSON::toString(source,false));
129+
duplicateAcrossChannels.getProperty("channels",{})[1].getDynamicObject()
130+
->setProperty("inserts",
131+
duplicateAcrossChannels.getProperty("channels",{})[0]
132+
.getProperty("inserts",{}));
133+
rejectUnchanged(duplicateAcrossChannels);
134+
135+
auto duplicateSameChannel=juce::JSON::parse(
136+
juce::JSON::toString(source,false));
137+
auto* existing=duplicateSameChannel.getProperty("channels",{})[0]
138+
.getProperty("inserts",{}).getArray();
139+
assert(existing && existing->size()==1);
140+
existing->add(juce::JSON::parse(juce::JSON::toString((*existing)[0],false)));
141+
rejectUnchanged(duplicateSameChannel);
142+
143+
auto overfullRack=juce::JSON::parse(
144+
juce::JSON::toString(source,false));
145+
juce::Array<juce::var> nine;
146+
for(int i=0;i<9;++i) {
147+
auto fx=std::make_unique<juce::DynamicObject>();
148+
fx->setProperty("instanceId","unique-FX-"+juce::String(i+1));
149+
fx->setProperty("id","vendor.eq.catalog");
150+
fx->setProperty("name","Vendor EQ");
151+
fx->setProperty("bypassed",false);
152+
nine.add(juce::var(fx.release()));
153+
}
154+
overfullRack.getProperty("channels",{})[0].getDynamicObject()
155+
->setProperty("inserts",juce::var(nine));
156+
rejectUnchanged(overfullRack);
117157
}
118158

119159
static void noMutationOnReject(juce::var snapshot,juce::var bus,bool admitted) {

0 commit comments

Comments
 (0)