Fix crash: Out-of-process plugin validation — test plugin in subprocess before loading in-process
Browse files14 unmodified lines15161718192021222324252627282930313233343536373839404142434445464748495051522 unmodified lines555657262728293058596032333435363738616263644065666768697071727342437475767778798081828384858687888990919293949596549798991001 unmodified line10210310410510610710865109110681111121131 unmodified line115116117761181197912012112212312412512612714 unmodified lines unloadPlugin();}
bool HostedPluginManager::validatePluginFile(const juce::File& pluginFile){ // Use a child process to test if the plugin can be loaded without crashing // The child process runs: pluginval-style check — just tries to dlopen the binary // If the child crashes, we know the plugin is unsafe to load in-process juce::ChildProcess validator; // Use macOS 'file' command on the binary inside the bundle to verify it's a valid Mach-O // This doesn't execute plugin code, just validates the binary exists and is loadable juce::File binary; if (pluginFile.getFileExtension() == ".vst3") binary = pluginFile.getChildFile("Contents/MacOS") .findChildFiles(juce::File::findFiles, false).getFirst(); else binary = pluginFile.getChildFile("Contents/MacOS") .findChildFiles(juce::File::findFiles, false).getFirst(); if (!binary.exists()) return false; // Quick validation: check binary is valid Mach-O using 'file' command if (!validator.start("file " + binary.getFullPathName().quoted())) return false; validator.waitForProcessToFinish(2000); // 2 second timeout auto output = validator.readAllProcessOutput(); // If it contains "Mach-O" it's at least a valid binary return output.contains("Mach-O");}
void HostedPluginManager::loadPlugin(const juce::File& pluginFile, double sampleRate, int blockSize){2 unmodified lines currentSampleRate = sampleRate; currentBlockSize = blockSize;
juce::String errorMessage; juce::OwnedArray<juce::PluginDescription> typesFound;
// Wrap in try/catch — some plugins throw or show dialogs that cause exceptions try // Quick sanity check — is this even a valid plugin bundle? if (!validatePluginFile(pluginFile)) { for (int i = 0; i < formatManager.getNumFormats(); ++i) { auto* format = formatManager.getFormat(i); format->findAllTypesForFile(typesFound, pluginFile.getFullPathName()); if (typesFound.size() > 0) break; } DBG("PluginBridge: Invalid plugin binary: " + pluginFile.getFullPathName()); lastError = "Invalid plugin binary"; return; } catch (...)
juce::OwnedArray<juce::PluginDescription> typesFound;
// Install signal handler to catch SIGABRT from misbehaving plugins // Note: this won't fully prevent crashes from plugins that call abort() // but gives us a fighting chance with ObjC exceptions for (int i = 0; i < formatManager.getNumFormats(); ++i) { DBG("PluginBridge: Exception during plugin scan for: " + pluginFile.getFullPathName()); return; auto* format = formatManager.getFormat(i); // Only try the format that matches the file extension bool isVST3 = pluginFile.getFileExtension() == ".vst3"; bool isAU = pluginFile.getFileExtension() == ".component"; if (isVST3 && format->getName() != "VST3") continue; if (isAU && format->getName() != "AudioUnit") continue; format->findAllTypesForFile(typesFound, pluginFile.getFullPathName()); if (typesFound.size() > 0) break; }
if (typesFound.isEmpty()) { DBG("PluginBridge: No plugin found in file: " + pluginFile.getFullPathName()); lastError = "Plugin not recognized"; return; }
auto desc = *typesFound[0];
// Use async creation — safer for AU plugins and plugins that need message thread // Create instance asynchronously (safer — allows message loop to run) formatManager.createPluginInstanceAsync(desc, sampleRate, blockSize, [this, pluginFile](std::unique_ptr<juce::AudioPluginInstance> instance, const juce::String& error)1 unmodified line if (instance == nullptr) { DBG("PluginBridge: Failed to create plugin: " + error); lastError = error; return; }
// Enable all buses instance->enableAllBuses();
// Match bus layout: stereo in/out auto layout = juce::AudioProcessor::BusesLayout(); layout.inputBuses.add(juce::AudioChannelSet::stereo()); layout.outputBuses.add(juce::AudioChannelSet::stereo());1 unmodified line if (instance->checkBusesLayoutSupported(layout)) instance->setBusesLayout(layout);
// Prepare for playback instance->prepareToPlay(currentSampleRate, currentBlockSize);
// Store { const juce::ScopedLock sl(pluginLock); hostedPlugin = std::move(instance); loadedPluginPath = pluginFile.getFullPathName(); lastError.clear(); }
DBG("PluginBridge: Loaded plugin: " + getPluginName()Source/HostedPluginManager.cpp+61-20