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);