From 6d54057c7fa1a736d02672e77a10218dff6c564c Mon Sep 17 00:00:00 2001 From: hogliux Date: Wed, 10 May 2017 16:34:44 +0100 Subject: [PATCH] VST2: Fixed a nullptr dereference in the VST2 wrapper if hosts supply nullptr buffer --- .../VST/juce_VST_Wrapper.cpp | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp index 6525bb454e..63f4612348 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp @@ -428,7 +428,8 @@ public: if (filter->isSuspended()) { for (int i = 0; i < numOut; ++i) - FloatVectorOperations::clear (outputs[i], numSamples); + if (outputs[i] != nullptr) + FloatVectorOperations::clear (outputs[i], numSamples); } else { @@ -441,18 +442,26 @@ public: { chan = outputs[i]; - // if some output channels are disabled, some hosts supply the same buffer - // for multiple channels - this buggers up our method of copying the - // inputs over the outputs, so we need to create unique temp buffers in this case.. + bool bufferPointerReusedForOtherChannels = false; + for (int j = i; --j >= 0;) { if (outputs[j] == chan) { - chan = new FloatType [(size_t) blockSize * 2]; - tmpBuffers.tempChannels.set (i, chan); + bufferPointerReusedForOtherChannels = true; break; } } + + // if some output channels are disabled, some hosts supply the same buffer + // for multiple channels or supply a nullptr - this buggers up our method + // of copying the inputs over the outputs, so we need to create unique temp + // buffers in this case.. + if (bufferPointerReusedForOtherChannels || chan == nullptr) + { + chan = new FloatType [(size_t) blockSize * 2]; + tmpBuffers.tempChannels.set (i, chan); + } } if (i < numIn)