implement Helper test-load: spawns Helper before in-process load, blocks crashy plugins
Browse filesNow loadPlugin() does:
1. Check blocklist → skip if blocked
2. Spawn PluginBridgeHelper --test '/path' → wait for exit
3. Exit code 0 → safe → load in-process
4. Exit code != 0 or crash → add to blocklist → show error → Ableton stays alive
This prevents Kickstart 2 / Ozone 12 / any crashy plugin from ever
crashing Ableton. The Helper takes the hit instead.
1 unmodified line23456789101112131460 unmodified lines757677717879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517677177178179180811811821831845 unmodified lines1901911929319319419519619719819920020120220320420520617 unmodified lines2242252261172272282291 unmodified line231232233125234235236231 unmodified lines4684694703633643653663673683693703713723734714724731 unmodified line#include "PluginBridgeEditor.h"#include "McpServer.h"
#include <spawn.h>#include <sys/wait.h>#include <unistd.h>#include <signal.h>
extern char** environ;
#include "json.hpp"using json = nlohmann::json;
60 unmodified lines return new PluginBridgeEditor(*this);}
// --- Plugin Loading (IN-PROCESS) ---// --- Helper Test Load ---// Spawns PluginBridgeHelper in a separate process to test if a plugin is safe.// If the helper crashes, Ableton stays alive and the plugin gets blocklisted.
static juce::File findHelperBinary(){ // Helper is bundled inside PluginBridge.vst3/Contents/Resources/ auto helper = juce::File::getSpecialLocation(juce::File::currentExecutableFile) .getParentDirectory() // MacOS/ .getParentDirectory() // Contents/ .getChildFile("Resources") .getChildFile(PluginBridgeConstants::kHelperBinaryName);
if (helper.exists()) return helper;
// Fallback: same directory as executable helper = juce::File::getSpecialLocation(juce::File::currentExecutableFile) .getParentDirectory() .getChildFile(PluginBridgeConstants::kHelperBinaryName);
return helper;}
PluginBridgeProcessor::TestResult PluginBridgeProcessor::testPluginSafety(const juce::String& path){ if (blocklist.isBlocked(path)) return TestResult::Unsafe;
auto helperBinary = findHelperBinary(); if (!helperBinary.exists()) { DBG("testPluginSafety: Helper binary not found, skipping test"); return TestResult::Safe; // Can't test — assume safe }
auto helperPathStr = helperBinary.getFullPathName().toStdString(); auto pluginPathStr = path.toStdString();
pid_t pid; char* argv[] = { (char*)helperPathStr.c_str(), (char*)"--test", (char*)pluginPathStr.c_str(), nullptr };
int spawnResult = posix_spawn(&pid, helperPathStr.c_str(), nullptr, nullptr, argv, environ); if (spawnResult != 0) { DBG("testPluginSafety: Failed to spawn helper"); return TestResult::Safe; // Can't test — assume safe }
// Wait for helper to exit (max 10 seconds) int status = 0; int waitResult = 0; int waitedMs = 0; const int timeoutMs = 10000;
while (waitedMs < timeoutMs) { waitResult = waitpid(pid, &status, WNOHANG); if (waitResult == pid) break; if (waitResult < 0) break;
usleep(50000); // 50ms waitedMs += 50; }
// Timeout — kill it and assume unsafe if (waitedMs >= timeoutMs) { kill(pid, SIGKILL); waitpid(pid, &status, 0); DBG("testPluginSafety: Helper timed out for " + path); return TestResult::Unsafe; }
// Check exit status if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { DBG("testPluginSafety: Plugin is SAFE: " + path); return TestResult::Safe; }
// Crashed or non-zero exit DBG("testPluginSafety: Plugin is UNSAFE: " + path); return TestResult::Unsafe;}
// --- Plugin Loading (IN-PROCESS, with safety test first) ---
void PluginBridgeProcessor::loadPlugin(const juce::String& path){ unloadPlugin();
// Check blocklist // 1. Check blocklist if (blocklist.isBlocked(path)) { if (onLoadFailed) onLoadFailed("Plugin is blocklisted (crashed previously)"); onLoadFailed("Not compatible (crashed previously)"); return; }
5 unmodified lines return; }
// Find plugin description // 2. Test safety in Helper process FIRST auto testResult = testPluginSafety(path); if (testResult == TestResult::Unsafe) { blocklist.addBlocked(path); if (onLoadFailed) onLoadFailed("Not compatible with PluginBridge"); return; }
// 3. Safe — load in-process juce::OwnedArray<juce::PluginDescription> typesFound;
for (int i = 0; i < formatManager.getNumFormats(); ++i)17 unmodified lines return; }
// Create plugin instance juce::String errorMessage; auto instance = formatManager.createPluginInstance( *typesFound[0], currentSampleRate, currentBlockSize, errorMessage);1 unmodified line if (instance == nullptr) { DBG("PluginBridgeProcessor: Failed to load: " + errorMessage); // Add to blocklist if it fails blocklist.addBlocked(path); if (onLoadFailed) onLoadFailed("Failed to load: " + errorMessage);231 unmodified lines return mcpServer ? mcpServer->getPort() : 0;}
// --- Test Safety (Helper-based) ---
PluginBridgeProcessor::TestResult PluginBridgeProcessor::testPluginSafety(const juce::String& path){ // TODO: Spawn helper to test-load plugin // For now, all plugins are treated as safe unless blocklisted if (blocklist.isBlocked(path)) return TestResult::Unsafe; return TestResult::Safe;}
// --- Entry Point ---
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()Source/Plugin/PluginBridgeProcessor.cpp+114-17