Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/NativeBuiltInFx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <array>
#include <cmath>
#include <memory>
#include <span>
#include <string_view>
Expand Down Expand Up @@ -35,7 +37,15 @@ std::unique_ptr<juce::AudioProcessor> 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<Processor>();
Expand Down
25 changes: 24 additions & 1 deletion tests/native_fx_registry_extension_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<double>::quiet_NaN(),
std::numeric_limits<double>::infinity(),
-std::numeric_limits<double>::infinity(),
0.,7999.,384001.}) {
assert(!found->prepare(rate,128,&gain,sizeof(gain)));
}
for(int frames:{-1,0,1,15,8193,std::numeric_limits<int>::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);
Expand Down
Loading