diff --git a/.github/workflows/p1-windows.yml b/.github/workflows/p1-windows.yml index 7719105c5..371589320 100644 --- a/.github/workflows/p1-windows.yml +++ b/.github/workflows/p1-windows.yml @@ -138,6 +138,8 @@ jobs: node --test tests/workstream_coordination_contract.test.mjs tests/ci_workflow_efficiency_test.mjs tests/chat_ci_dispatch_contract.test.mjs tests/approved_native_m2_contract.test.cjs tests/native_artifact_packaging_contract_test.mjs tests/windows_installer_contract_test.mjs tests/live_graph_contract_test.mjs tests/native_caption_wire_geometry_contract.test.cjs python -m unittest discover -s tests -p approved_native_gui_bundle_test.py -v python -m unittest discover -s scripts/tests -p test_factoryfx_release_bundle.py -v + - name: WaveShell JUCE 8 class-index regression (no paid Windows) + run: python -m unittest discover -s tests -p test_waveshell_juce_patch.py -v - name: Compressor exact-source native CPU A/B (same runner, non-gating timing) if: ${{ github.event_name == 'pull_request' && startsWith(github.head_ref, 'perf/compressor-') }} run: python scripts/benchmark_compressor_ab.py --reference 043748a552e66fd72e217cbf66aa35e6cc3e0b21 diff --git a/CMakeLists.txt b/CMakeLists.txt index 35fef2ded..a6440f98d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,20 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) if (NOT DEFINED JUCE_ROOT) message(FATAL_ERROR "Pass -DJUCE_ROOT=C:/path/to/JUCE (8.0.15+ required)") endif() -add_subdirectory("${JUCE_ROOT}" "${CMAKE_BINARY_DIR}/juce") - find_package(Python3 REQUIRED COMPONENTS Interpreter) +# JUCE 8.0.15 WaveShell class indices move after setHostContext. +# Apply audited upstream 3fa28d0 ordering correction before compilation. +execute_process( + COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/patch_juce_vst3_waveshell.py" + --juce-root "${JUCE_ROOT}" + RESULT_VARIABLE ARMIX_WAVESHELL_PATCH_RESULT + OUTPUT_VARIABLE ARMIX_WAVESHELL_PATCH_MESSAGE + ERROR_VARIABLE ARMIX_WAVESHELL_PATCH_ERROR) +if(NOT ARMIX_WAVESHELL_PATCH_RESULT EQUAL 0) + message(FATAL_ERROR "JUCE WaveShell VST3 host fix not verified: ${ARMIX_WAVESHELL_PATCH_ERROR}") +endif() +message(STATUS "${ARMIX_WAVESHELL_PATCH_MESSAGE}") +add_subdirectory("${JUCE_ROOT}" "${CMAKE_BINARY_DIR}/juce") # The independent exact-byte verifier must use the SAME Python interpreter # selected by CMake to generate compressed favicon/PNG resources (Windows # runners can have several Python versions with different zlib builds). @@ -276,6 +287,16 @@ if(BUILD_TESTING) juce::juce_audio_devices juce::juce_recommended_config_flags) target_compile_features(ARMixDeviceApplyCoordinatorTests PRIVATE cxx_std_20) add_test(NAME NativeDeviceApplyPinValidationAndRollbackEvidence COMMAND ARMixDeviceApplyCoordinatorTests) + juce_add_console_app(ARMixVst3StartupSafetyTests PRODUCT_NAME "ArSonMix Waves VST3 Identity and Recovery Tests") + target_sources(ARMixVst3StartupSafetyTests PRIVATE + tests/vst3_waves_identity_startup_test.cpp + src/Vst3DescriptionCache.h src/StartupVst3RecoveryGuard.h) + target_link_libraries(ARMixVst3StartupSafetyTests PRIVATE + juce::juce_audio_processors juce::juce_recommended_config_flags) + target_compile_features(ARMixVst3StartupSafetyTests PRIVATE cxx_std_20) + add_test(NAME WavesVst3IdentityAndStartupCrashRecovery COMMAND ARMixVst3StartupSafetyTests) + add_test(NAME Vst3WaveShellHostContextOrderingFixture + COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_waveshell_juce_patch.py") add_executable(ARMixLiveRoutingEpochTests tests/live_port_epoch_publisher_test.cpp) target_compile_features(ARMixLiveRoutingEpochTests PRIVATE cxx_std_20) add_test(NAME P1ELivePortGenerationRevisionAndRealtimeRetirement COMMAND ARMixLiveRoutingEpochTests) diff --git a/docs/architecture/README.md b/docs/architecture/README.md index 8b1096a27..c0e6c90d6 100644 --- a/docs/architecture/README.md +++ b/docs/architecture/README.md @@ -40,6 +40,7 @@ Assembled /preview/ DOM (presentation only) | Modal setup transaction (M2b) | src/Main.cpp::showDeviceSetup; NativeDeviceApplyCoordinator.h | Persistent one-owner lease across visible JUCE selector, explicit Apply and automatic ASIO restart; repeated Setup clicks never re-mute; selector close completes readback/rebind before releasing lease | | Live hardware readback (M2c) | src/NativeDeviceApplyCoordinator.h; src/Main.cpp | Consolidated actual device-object readback on CONTROL, strict ASIO driver instance identity and live mask/rate/buffer verification before Apply/rollback; no new device owner or callback | | Production audio compatibility | src/LiveDryRoutingLab.h; engine/core/UnifiedLegacyProductionAdmission.h | Retain only proven required M4/FAT migration semantics; never create another render authority | +| Waves VST3 / crash-safe recovery | scripts/patch_juce_vst3_waveshell.py; src/Vst3DescriptionCache.h; src/StartupVst3RecoveryGuard.h | Correct JUCE 8 WaveShell class-ordering defect; require name+UID resolution; protect saved .smix from repeated startup vendor crashes | | M3a actual render evidence | engine/core/ProductionRenderAudit.h; LiveDryRoutingLab::process/status; docs/architecture/M3_RENDER_PATH_EVIDENCE_20261111.md | One native or M4 render attempt per JUCE callback; success/fault/overlap and muted/unpatched readback; no audio authority change | | Built-in DSP and VST lifecycle | engine/builtin_fx/**; src/NativeBuiltInFx.h; src/FactoryFxRegistry.h; src/PluginCatalog.h; engine/core/DynamicChannelFxLeaseBank.h; src/LiveAudioEngine.h | Per-processor DSP; one built-in registration for live insert, offline prepare, restore and native picker. Specialized editors and vendor lease remain with their existing owners. | | Player | engine/player/**; src/Main.cpp dispatch | Worker decode / buffered PCM, one native graph virtual input, no independent hardware output callback | diff --git a/docs/architecture/WAVESHELL_STARTUP_RECOVERY_20261111.md b/docs/architecture/WAVESHELL_STARTUP_RECOVERY_20261111.md new file mode 100644 index 000000000..bb1fe66e6 --- /dev/null +++ b/docs/architecture/WAVESHELL_STARTUP_RECOVERY_20261111.md @@ -0,0 +1,30 @@ +# WaveShell identity and startup recovery — P0 + +Root cause: ArSonMix pins JUCE 8.0.15; its VST3ModuleHandle::create resolves +a class index before IPluginFactory3::setHostContext. Waves WaveShell can +re-enumerate its factory at setHostContext, shifting indices and opening +an entirely different plugin. JUCE fixed this on 2026-09-03 in commit +3fa28d0a14f1be97d49603c710afaa6b9b900cdb. + +scripts/patch_juce_vst3_waveshell.py applies the exact necessary ordering +change to pinned JUCE 8 before compilation. Unknown or partial sources +fail CMake configure rather than ship a silently vulnerable VST3 host. +Tests enforce idempotence and host-context-before-class-index ordering. + +DescriptionCache::choose now selects by exact catalog product name and +JUCE 32-bit UID, rejecting collisions. Direct ADD, native ChannelId ADD, +legacy and saved-session restore pass the expected name. Catalog keys and +the .smix schema are preserved; a mismatched old catalog fails closed. + +Crash-safe startup: Vst3RestoreCrashGuard records automatic saved-FX restore +before instantiating any VST3 vendor module. An abnormal termination leaves +the marker. The next launch opens the GUI and does not repeat automatic +FX restore; saved .smix, preset binaries and factory plugins remain intact. +After 15 seconds of normal post-restore operation, or normal application +shutdown, the marker is cleared. A read-only settings folder fails safe. +User can manually Open after investigating/updating the affected VST3. + +This guards crashes within startup FX restore, not all possible startup +crash causes: gather WER dump and machine audio/WebView2 diagnostics. +Physical WaveShell v17 listening, GUI/editor identity and restored sessions +must be tested on a licensed user's machine. This is not physical FAT proof. diff --git a/scripts/patch_juce_vst3_waveshell.py b/scripts/patch_juce_vst3_waveshell.py new file mode 100644 index 000000000..e1ca71557 --- /dev/null +++ b/scripts/patch_juce_vst3_waveshell.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +"""Apply JUCE's 2026 WaveShell host-context ordering fix to pinned JUCE 8. + +The repository intentionally pins JUCE 8.0.15 for the verified native host. +JUCE upstream 3fa28d0 (2026-09-03) fixes WaveShell class-list mutation: +the factory must receive setHostContext BEFORE resolving a class index. +Patch only the three pinned-JUCE anchors, idempotently, or fail closed. +Never patch a different/unknown JUCE implementation silently. +""" +import argparse +from pathlib import Path + +RELATIVE = Path("modules/juce_audio_processors_headless/format_types/juce_VST3PluginFormatImpl.h") + +OLD = ( + "static VST3ModuleHandle create (const File& pluginFile, const PluginDescription& desc)", + " const auto numClasses = factory->countClasses();\n" + " result.classIndex = findClassMatchingDescription (factory, desc);", + "const auto module = VST3ModuleHandle::create (file, description);", +) +NEW = ( + "static VST3ModuleHandle create (const File& pluginFile, const PluginDescription& desc, FUnknown* hostContext)", + " // JUCE upstream 3fa28d0: WaveShell changes class indices in setHostContext.\n" + " // Resolve the class index only AFTER the same host context is set.\n" + " if (VSTComSmartPtr pf3; pf3.loadFrom (factory.get()))\n" + " pf3->setHostContext (hostContext);\n" + " const auto numClasses = factory->countClasses();\n" + " result.classIndex = findClassMatchingDescription (factory, desc);", + "const auto module = VST3ModuleHandle::create (file, description, host->getFUnknown());", +) + + +def apply_patch(source: str) -> tuple[str, bool]: + # We deliberately support only the audited JUCE 8.0.15 implementation. + if all(source.count(after) == 1 for after in NEW): + return source, False + if any(source.count(before) != 1 for before in OLD): + raise ValueError("JUCE_VST3_WAVESHELL_PATCH_UNSUPPORTED_SOURCE") + if any(after in source for after in NEW): + raise ValueError("JUCE_VST3_WAVESHELL_PATCH_PARTIAL_SOURCE") + updated = source + for before, after in zip(OLD, NEW): + updated = updated.replace(before, after, 1) + if not all(updated.count(after) == 1 for after in NEW): + raise ValueError("JUCE_VST3_WAVESHELL_PATCH_POSTCONDITION_FAILED") + return updated, True + + +def patch_root(root: Path) -> bool: + target = root / RELATIVE + if not target.is_file(): + raise FileNotFoundError(f"JUCE_VST3_WAVESHELL_SOURCE_MISSING: {target}") + original = target.read_text(encoding="utf-8") + changed, modified = apply_patch(original) + if modified: + target.write_text(changed, encoding="utf-8") + return modified + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--juce-root", type=Path, required=True) + args = parser.parse_args() + try: + modified = patch_root(args.juce_root) + except (OSError, ValueError) as exc: + parser.exit(1, f"{exc}\n") + print("JUCE_VST3_WAVESHELL_CONTEXT_ORDER=" + ("PATCHED" if modified else "VERIFIED")) diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index 006d75a64..8411366b6 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -1027,7 +1027,8 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback } juce::String addVst3(const juce::String& filename,int uid, - const juce::String& catalogId) + const juce::String& catalogId, + const juce::String& expectedName={}) { if(independent_.active())return "Return to DIRECT mode before editing VST3"; if(handoff_.busy() || fxMovePhase_.load(std::memory_order_acquire)!=0) @@ -1044,7 +1045,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback const auto frames=juce::jmax(32,device->getCurrentBufferSizeSamples()); if(!(rate>0.0) || frames>maxFrames) return "Unsupported device sample rate or buffer quantum"; - const auto chosen=armix::vst::DescriptionCache::resolve(*fmt,filename,uid); + const auto chosen=armix::vst::DescriptionCache::resolve(*fmt,filename,uid,expectedName); if(!chosen)return "Effect identity not found inside VST3 module"; juce::String error; auto instance=formats_.createPluginInstance(*chosen,rate,frames,error); @@ -1152,7 +1153,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback if (fx.binary.getSize() > armix::storage::NativePresetArchive::maxStateBytes || !juce::File (fx.path).exists() || !fx.path.endsWithIgnoreCase (".vst3")) return "Plugin is missing or invalid: " + fx.name; - const auto match=armix::vst::DescriptionCache::resolve(*fmt,fx.path,fx.uid); + const auto match=armix::vst::DescriptionCache::resolve(*fmt,fx.path,fx.uid,fx.name); if (!match) return "VST3 plugin identity missing: " + fx.name; juce::String error; @@ -2071,7 +2072,8 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback LiveDryRoutingLab::NativeBusResult installNativeVst3( std::uint64_t ep,std::uint64_t pcmRevision, std::uint64_t rosterRevision,armix::mixer::ChannelId id, - const juce::String& path,int uid,const juce::String& catalogId) { + const juce::String& path,int uid,const juce::String& catalogId, + const juce::String& expectedName={}) { LiveDryRoutingLab::NativeBusResult fail{}; fail.error="NATIVE_VST3_HOST_UNAVAILABLE"; auto* device=deviceManager_.getCurrentAudioDevice(); @@ -2091,7 +2093,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback if(!fmt||!fmt->fileMightContainThisPluginType(path)) {fail.error="NATIVE_VST3_MODULE_NOT_FOUND";return fail;} try { - const auto chosen=armix::vst::DescriptionCache::resolve(*fmt,path,uid); + const auto chosen=armix::vst::DescriptionCache::resolve(*fmt,path,uid,expectedName); if(!chosen){fail.error="NATIVE_VST3_IDENTITY_NOT_FOUND";return fail;} juce::String pluginError; auto instance=formats_.createPluginInstance(*chosen,rate, diff --git a/src/Main.cpp b/src/Main.cpp index 8fd58c156..cd336646a 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -30,6 +30,7 @@ #endif #endif #include "PluginCatalog.h" +#include "StartupVst3RecoveryGuard.h" #include "PortableWorkspace.h" #include "StudioBackup.h" #include "NativeLiveShowCapture.h" @@ -386,6 +387,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr diagnostics_.record("DYNAMIC_MIXER_EXIT_SAVE_REJECTED",error); } engine_.stop(); + // Normal shutdown is not an interrupted startup. Leave marker intact + // on abnormal vendor termination (destructors never run). + if(startupFxGuard_)(void)startupFxGuard_->complete(); browser_.setVisible (false); setLookAndFeel (nullptr); // before the owned LookAndFeel is destroyed } @@ -434,6 +438,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr juce::String mixerSessionError_,lastMixerSessionFingerprint_; bool mixerSessionStartupInspected_=false; bool mixerSessionRecoveryPending_=false; + std::unique_ptr startupFxGuard_; + juce::uint32 startupFxGuardTick_=0; std::unique_ptr mixerFileChooser_; bool mixerFileDialogOpen_=false; juce::File lastMixerFile_; @@ -1629,7 +1635,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr *builtIn,ep,rev,roster,armix::mixer::ChannelId{target}): engine_.installNativeVst3( ep,rev,roster,armix::mixer::ChannelId{target}, - plugin->path,plugin->uid,plugin->key()); + plugin->path,plugin->uid,plugin->key(),plugin->name); applied=result.accepted && result.error && result.error[0]==0; if(!applied)nativeError=result.error; @@ -5724,7 +5730,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr closePluginEditor(); try { - error = engine_.addVst3 (plugin->path, plugin->uid, plugin->key()); + error = engine_.addVst3 (plugin->path, plugin->uid, plugin->key(),plugin->name); } catch (const std::exception& ex) { @@ -6204,13 +6210,44 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr mixerSessionStartupInspected_=true; if(armix::session::NativeMixerSessionStore(settingsDirectory()).exists()){ mixerSessionRecoveryPending_=true; - const auto error=restoreSavedMixerSession(startupError_.isEmpty()); - if(error.isNotEmpty()) - emitNotice(error.startsWith("NEEDS_REMAP:")?error.fromFirstOccurrenceOf(": ",false,false):error,true); - else - deviceSettingsDirty_=true; + auto guard=std::make_unique(settingsDirectory()); + // A crash in vendor DLL code bypasses C++ exception handling. + // Preserve the user's .smix without replaying its FX at every + // launch. Manual Open remains available after diagnosis. + if(guard->interrupted()) { + mixerSessionStatus_="STARTUP_FX_SAFE_RECOVERY"; + mixerSessionError_="Previous startup ended during FX restore. " + "Session preserved; reopen it manually after checking VST3 plugins."; + diagnostics_.record("STARTUP_FX_RESTORE_CRASH_GUARD",mixerSessionError_); + emitNotice(mixerSessionError_,true); + } else if(!guard->arm()) { + mixerSessionStatus_="STARTUP_FX_RESTORE_UNAVAILABLE"; + mixerSessionError_="Unable to protect saved FX startup. " + "Session preserved; check the settings folder permissions."; + diagnostics_.record("STARTUP_FX_RESTORE_GUARD_IO",mixerSessionError_); + emitNotice(mixerSessionError_,true); + } else { + startupFxGuard_=std::move(guard); + const auto error=restoreSavedMixerSession(startupError_.isEmpty()); + if(error.isNotEmpty()) { + (void)startupFxGuard_->complete(); + startupFxGuard_.reset(); + emitNotice(error.startsWith("NEEDS_REMAP:")? + error.fromFirstOccurrenceOf(": ",false,false):error,true); + } else { + // Count stability only after vendor construction. + startupFxGuardTick_=juce::Time::getMillisecondCounter(); + deviceSettingsDirty_=true; + } + } }else if(startupError_.isEmpty())requestAutomaticMain(); } + // Do not clear the marker as soon as constructors return: Waves and + // other VST3 vendors may crash in their first audio callbacks. + if(startupFxGuard_ && browser_.loaded && + juce::Time::getMillisecondCounter()-startupFxGuardTick_>=15000u) { + if(startupFxGuard_->complete())startupFxGuard_.reset(); + } serviceAsioMixerRestart(); // ONE actionable notice per unexpected DIRECT reroute. The audio // callback has already zero-filled output atomically; status, log and diff --git a/src/NativeMixerSessionFxRestore.h b/src/NativeMixerSessionFxRestore.h index a3a3b545d..2af4d5240 100644 --- a/src/NativeMixerSessionFxRestore.h +++ b/src/NativeMixerSessionFxRestore.h @@ -37,7 +37,7 @@ class NativeMixerSessionFxRestore final { auto* format=formats.getFormat(0); if(!format || !format->fileMightContainThisPluginType(insert.path)) return "Saved VST3 unavailable: "+insert.catalogId; - const auto chosen=armix::vst::DescriptionCache::resolve(*format,insert.path,insert.uid); + const auto chosen=armix::vst::DescriptionCache::resolve(*format,insert.path,insert.uid,insert.name); if(!chosen)return "Saved VST3 identity not found: "+insert.catalogId; juce::String pluginError; auto processor=formats.createPluginInstance(*chosen,sampleRate,frames,pluginError); diff --git a/src/StartupVst3RecoveryGuard.h b/src/StartupVst3RecoveryGuard.h new file mode 100644 index 000000000..fe88047a4 --- /dev/null +++ b/src/StartupVst3RecoveryGuard.h @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include + +namespace armix::startup { +// A process crash inside a third-party VST3 DLL cannot be caught by JUCE or +// C++ exception handlers. Mark automatic FX restore BEFORE loading vendor code. +// An interrupted prior startup must NOT replay that same potentially crashing +// session forever. Keep .smix and plugin state untouched; manual Open remains +// available after diagnosing the vendor. Only CONTROL thread touches this file. +class Vst3RestoreCrashGuard final { +public: + explicit Vst3RestoreCrashGuard(const juce::File& settingsRoot) + : marker_(settingsRoot.getChildFile("startup-vst3-restore.pending")) {} + + [[nodiscard]] bool interrupted() const { return marker_.existsAsFile(); } + + [[nodiscard]] bool arm() { + if (interrupted()) return false; // never overwrite crash evidence + return marker_.replaceWithText("RESTORE_IN_PROGRESS\n"); + } + + [[nodiscard]] bool complete() { + // Called after stable startup or graceful shutdown, never while + // processor construction is still underway. + return !marker_.existsAsFile() || marker_.deleteFile(); + } +private: + juce::File marker_; +}; +} // namespace armix::startup diff --git a/src/Vst3DescriptionCache.h b/src/Vst3DescriptionCache.h index aa8f43ab9..70e838674 100644 --- a/src/Vst3DescriptionCache.h +++ b/src/Vst3DescriptionCache.h @@ -13,20 +13,35 @@ class DescriptionCache final { public: using Descriptions=juce::OwnedArray; + // WaveShell can expose hundreds of classes from the same module. + // Enumeration index and JUCE's 32-bit UID alone cannot disambiguate. + // Reject all ambiguous matches rather than load a different product. + static std::optional choose( + const Descriptions& descriptions,int uid, + const juce::String& name={}) { + const juce::PluginDescription* selected=nullptr; + for(const auto* item:descriptions) { + if(!item||item->isInstrument||item->uniqueId!=uid|| + (name.isNotEmpty()&&!item->name.equalsIgnoreCase(name)))continue; + if(selected)return {}; + selected=item; + } + return selected?std::optional(*selected):std::nullopt; + } + static std::optional resolve( - juce::AudioPluginFormat& format,const juce::String& path,int uid) { + juce::AudioPluginFormat& format,const juce::String& path,int uid, + const juce::String& expectedName={}) { if(!format.fileMightContainThisPluginType(path))return {}; DescriptionCache cache; - if(auto saved=cache.find(path,uid))return saved; + if(auto saved=cache.find(path,uid,expectedName))return saved; const auto stamp=moduleStamp(juce::File(path)); Descriptions discovered; format.findAllTypesForFile(discovered,path); // A module updated while scanning must not seed a warm cache. if(stamp.isNotEmpty()&&stamp==moduleStamp(juce::File(path))) cache.remember(discovered); - for(const auto* item:discovered) - if(item && item->uniqueId==uid && !item->isInstrument)return *item; - return {}; + return choose(discovered,uid,expectedName); } explicit DescriptionCache(juce::File root=storage::PortableWorkspace::machineDataRoot() @@ -50,11 +65,10 @@ class DescriptionCache final { } } - std::optional find(const juce::String& path,int uid) const { + std::optional find(const juce::String& path,int uid, + const juce::String& name={}) const { const auto descriptions=read(path); - for(const auto* item:descriptions) - if(item->uniqueId==uid && !item->isInstrument)return *item; - return {}; + return choose(descriptions,uid,name); } Descriptions read(const juce::String& path) const { diff --git a/tests/test_waveshell_juce_patch.py b/tests/test_waveshell_juce_patch.py new file mode 100644 index 000000000..61b834ba5 --- /dev/null +++ b/tests/test_waveshell_juce_patch.py @@ -0,0 +1,58 @@ +# SPDX-License-Identifier: AGPL-3.0-only +"""Fixture regression: WaveShell cannot load a class from pre-context index.""" +import sys +import tempfile +import unittest +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) +from patch_juce_vst3_waveshell import OLD, NEW, RELATIVE, apply_patch, patch_root + + +def vulnerable_fixture(): + return """ +struct VST3ModuleHandle final { + static VST3ModuleHandle create (const File& pluginFile, const PluginDescription& desc) + { + auto factory = result.handle->getPluginFactory(); + if (factory == nullptr) return {}; + const auto numClasses = factory->countClasses(); + result.classIndex = findClassMatchingDescription (factory, desc); + } +}; +static auto createVST3Instance(VSTComSmartPtr host) { + const auto module = VST3ModuleHandle::create (file, description); +} +""" + + +class WaveShellContextOrderTest(unittest.TestCase): + def test_patches_known_pinned_juce_source_and_is_idempotent(self): + fixed, modified = apply_patch(vulnerable_fixture()) + self.assertTrue(modified) + self.assertIn(NEW[0], fixed) + self.assertIn(NEW[2], fixed) + self.assertLess(fixed.index("pf3->setHostContext (hostContext)"), + fixed.index("findClassMatchingDescription (factory, desc)")) + self.assertEqual((fixed, False), apply_patch(fixed)) + + def test_unknown_or_partial_source_fails_closed(self): + with self.assertRaisesRegex(ValueError, "UNSUPPORTED_SOURCE"): + apply_patch("unknown JUCE source") + partial = vulnerable_fixture().replace(OLD[0], NEW[0]) + with self.assertRaisesRegex(ValueError, "UNSUPPORTED_SOURCE"): + apply_patch(partial) + + def test_patches_disk_copy_without_touching_other_files(self): + with tempfile.TemporaryDirectory() as d: + root = Path(d) + target = root / RELATIVE + target.parent.mkdir(parents=True) + target.write_text(vulnerable_fixture(), encoding="utf-8") + self.assertTrue(patch_root(root)) + self.assertFalse(patch_root(root)) + self.assertIn("host->getFUnknown()", target.read_text(encoding="utf-8")) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/vst3_waves_identity_startup_test.cpp b/tests/vst3_waves_identity_startup_test.cpp new file mode 100644 index 000000000..bad82332d --- /dev/null +++ b/tests/vst3_waves_identity_startup_test.cpp @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#ifdef NDEBUG +#undef NDEBUG +#endif +#include "../src/Vst3DescriptionCache.h" +#include "../src/StartupVst3RecoveryGuard.h" +#include +#include + +int main() { + using armix::vst::DescriptionCache; + DescriptionCache::Descriptions shell; + auto add=[&](const juce::String& name,int uid) { + auto d=std::make_unique(); + d->pluginFormatName="VST3"; + d->fileOrIdentifier="C:\\VST3\\WaveShell1-VST3 17.1.vst3"; + d->manufacturerName="Waves"; + d->name=name;d->uniqueId=uid;d->isInstrument=false; + shell.add(d.release()); + }; + // Synthetic UID collision and unstable WaveShell class order. The + // visible catalog name must NEVER resolve to another Waves product. + add("Saphira Stereo",42); + add("GW MixCentric Mono",42); + assert(DescriptionCache::choose(shell,42,"Saphira Stereo")->name=="Saphira Stereo"); + assert(DescriptionCache::choose(shell,42,"GW MixCentric Mono")->name=="GW MixCentric Mono"); + assert(!DescriptionCache::choose(shell,42)); // arbitrary first forbidden + assert(!DescriptionCache::choose(shell,42,"Unknown product")); + assert(!DescriptionCache::choose(shell,9,"Saphira Stereo")); + // Duplicate name + UID must not select the first arbitrary class. + add("Saphira Stereo",42); + assert(!DescriptionCache::choose(shell,42,"Saphira Stereo")); + + const auto temp=juce::File::getSpecialLocation(juce::File::tempDirectory) + .getChildFile("arsonmix-vst3-crash-guard-"+juce::Uuid().toString()); + assert(temp.createDirectory().wasOk()); + const auto session=temp.getChildFile("last-used.smix"); + assert(session.replaceWithText("PRESERVE_USER_SESSION")); + { + armix::startup::Vst3RestoreCrashGuard first(temp); + assert(!first.interrupted()); + assert(first.arm()); + assert(first.interrupted()); + // An actual plugin fault terminates the host before any C++ catch. + } + armix::startup::Vst3RestoreCrashGuard nextLaunch(temp); + assert(nextLaunch.interrupted()); + assert(!nextLaunch.arm()); + assert(session.loadFileAsString()=="PRESERVE_USER_SESSION"); + assert(nextLaunch.complete()); + assert(!nextLaunch.interrupted()); + assert(nextLaunch.arm()); + assert(nextLaunch.complete()); + assert(temp.deleteRecursively()); +}