Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.
Rust downloadmanagerguihacktoberfesthomebrewlightweightlinuxlinux-distributionlocal-firstmacosmacos-packagemedia-toolboxopen-sourcerustsveltetauritrendingtrending-repositorieswindowswindows-desktopytdlp
fix(plugins): reject ABI/toolchain-incompatible plugins instead of segfaulting
Antonio Leandro41dbc9feadac
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 8947cf58..a3d06e84 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -45,9 +45,12 @@ jobs:- name: Install frontend dependenciesrun: pnpm install- - name: Install Rust stable- uses: dtolnay/rust-toolchain@stable+ # Pinned via rust-toolchain.toml: the plugin ABI depends on the exact+ # rustc version, so this must match what the plugin repos build with.+ - name: Install Rust+ uses: dtolnay/rust-toolchain@masterwith:+ toolchain: 1.97.0targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}- name: Rust cachediff --git a/rust-toolchain.toml b/rust-toolchain.tomlnew file mode 100644index 00000000..c6cd0c61--- /dev/null+++ b/rust-toolchain.toml@@ -0,0 +1,12 @@+# Plugins are dynamic libraries that exchange Rust trait objects with the+# host. Rust guarantees no ABI stability across compiler releases, so a host+# and a plugin built with different rustc versions corrupt vtables and+# segfault at the first plugin call. The loader refuses to load plugins whose+# embedded rustc fingerprint differs from the host's, and this file pins the+# compiler so host and plugin builds agree by construction.+#+# Bumping this version requires rebuilding and re-releasing every plugin in+# tonhowtf/omniget-plugins. Keep it in sync across all plugin repos.+[toolchain]+channel = "1.97.0"+components = ["rustfmt", "clippy"]diff --git a/src-tauri/omniget-plugin-sdk/build.rs b/src-tauri/omniget-plugin-sdk/build.rsnew file mode 100644index 00000000..dbc6720f--- /dev/null+++ b/src-tauri/omniget-plugin-sdk/build.rs@@ -0,0 +1,22 @@+use std::process::Command;++// Capture the exact rustc that compiles this crate. Rust has no stable ABI:+// trait-object vtables, fat-pointer calling conventions and std type layouts+// may all change between compiler releases, so a plugin dylib is only safe to+// load into a host built by the *same* rustc. The version string (including+// the commit hash) is embedded in BUILD_INFO and exchanged through the+// `omniget_plugin_build_info` handshake symbol at load time.+fn main() {+ // Cargo sets RUSTC to the compiler used for the build.+ let rustc = std::env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string());+ let version = Command::new(&rustc)+ .arg("--version")+ .output()+ .ok()+ .filter(|o| o.status.success())+ .map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())+ .unwrap_or_else(|| "unknown".to_string());+ println!("cargo:rustc-env=OMNIGET_SDK_RUSTC_VERSION={version}");+ println!("cargo:rerun-if-env-changed=RUSTC");+ println!("cargo:rerun-if-env-changed=RUSTUP_TOOLCHAIN");+}diff --git a/src-tauri/omniget-plugin-sdk/src/lib.rs b/src-tauri/omniget-plugin-sdk/src/lib.rsindex 7cf2c2f8..dc4d9eb1 100644--- a/src-tauri/omniget-plugin-sdk/src/lib.rs+++ b/src-tauri/omniget-plugin-sdk/src/lib.rs@@ -6,4 +6,79 @@ pub use host::*;pub use manifest::*;pub use plugin::*;-pub const ABI_VERSION: u32 = 2;+/// Plugin ABI generation. The loader refuses to load any plugin whose+/// `omniget_plugin_abi_version` export does not return exactly this value.+///+/// History:+/// - v3 (2026-07-09): invalidates every plugin built before the platform/model+/// types moved into `omniget-core` (PR #163) and before the toolchain+/// handshake existed. v2 plugins passed the handshake but crashed with+/// SIGSEGV at first call because Rust trait objects and std type layouts are+/// not ABI-stable across differing crate/compiler versions. v3 plugins must+/// also export `omniget_plugin_build_info` (added automatically by+/// `export_plugin!`), which the loader uses to reject plugins built by a+/// different rustc than the host.+/// - v2: pre-2026-07 interface.+pub const ABI_VERSION: u32 = 3;++/// NUL-terminated build fingerprint exported by `export_plugin!` through the+/// `omniget_plugin_build_info` C symbol and compared by the host at load time.+///+/// Format: `sdk=<omniget-plugin-sdk version>;rustc=<rustc --version output>`.+/// The rustc component (compiler version + commit hash) is what actually+/// gates loading: `ABI_VERSION` alone cannot detect two builds of the same+/// SDK made by different compilers, and Rust makes no ABI-stability promise+/// across compiler releases.+pub const BUILD_INFO: &str = concat!(+ "sdk=",+ env!("CARGO_PKG_VERSION"),+ ";rustc=",+ env!("OMNIGET_SDK_RUSTC_VERSION"),+ "\0"+);++/// [`BUILD_INFO`] without the trailing NUL, for logging and comparison.+pub fn build_info_str() -> &'static str {+ BUILD_INFO.trim_end_matches('\0')+}++/// Extracts the `rustc=` component from a build-info string.+pub fn rustc_component(info: &str) -> Option<&str> {+ info.split(';').find_map(|kv| kv.strip_prefix("rustc="))+}++/// Extracts the `sdk=` component from a build-info string.+pub fn sdk_component(info: &str) -> Option<&str> {+ info.split(';').find_map(|kv| kv.strip_prefix("sdk="))+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn build_info_is_nul_terminated_c_string() {+ assert!(BUILD_INFO.ends_with('\0'));+ // exactly one NUL, so CStr::from_ptr on the host side sees the whole string+ assert_eq!(BUILD_INFO.matches('\0').count(), 1);+ }++ #[test]+ fn build_info_components_parse() {+ let info = build_info_str();+ assert_eq!(sdk_component(info), Some(env!("CARGO_PKG_VERSION")));+ let rustc = rustc_component(info).expect("rustc component present");+ // build.rs must have captured a real compiler version, e.g.+ // "rustc 1.96.0 (ac68faa20 2026-05-25)"+ assert!(+ rustc.starts_with("rustc "),+ "unexpected rustc fingerprint: {rustc}"+ );+ }++ #[test]+ fn mismatched_rustc_fingerprints_do_not_compare_equal() {+ let stale = "sdk=0.2.0;rustc=rustc 1.95.0 (59807616e 2026-04-10)";+ assert_ne!(rustc_component(stale), rustc_component(build_info_str()));+ }+}diff --git a/src-tauri/omniget-plugin-sdk/src/plugin.rs b/src-tauri/omniget-plugin-sdk/src/plugin.rsindex 48ca4b74..7c0ac0eb 100644--- a/src-tauri/omniget-plugin-sdk/src/plugin.rs+++ b/src-tauri/omniget-plugin-sdk/src/plugin.rs@@ -28,6 +28,17 @@ macro_rules! export_plugin {$crate::ABI_VERSION}+ /// Toolchain handshake (ABI v3+). Returns a NUL-terminated+ /// `sdk=...;rustc=...` fingerprint the host compares against its own+ /// before trusting any non-C-ABI boundary (trait objects, String,+ /// serde_json::Value, boxed futures). Thin `*const c_char` return is+ /// FFI-safe on every rustc, so this call is safe even on a mismatched+ /// toolchain — unlike everything it protects.+ #[no_mangle]+ pub extern "C" fn omniget_plugin_build_info() -> *const ::std::os::raw::c_char {+ $crate::BUILD_INFO.as_ptr() as *const ::std::os::raw::c_char+ }+#[no_mangle]pub extern "C" fn omniget_plugin_init() -> *mut dyn $crate::OmnigetPlugin {let plugin = $constructor;diff --git a/src-tauri/src/plugin_loader.rs b/src-tauri/src/plugin_loader.rsindex fe1fa487..5ddf64b7 100644--- a/src-tauri/src/plugin_loader.rs+++ b/src-tauri/src/plugin_loader.rs@@ -240,7 +240,7 @@ fn load_single_plugin(unsafe { lib.get(b"omniget_plugin_abi_version") }.map_err(|_| {PluginLoadError {message: format!(- "Missing omniget_plugin_abi_version symbol (plugin built against an older SDK; core expects ABI v{})",+ "This plugin was built for an older version of OmniGet (no ABI handshake; this version requires ABI v{}). Update the plugin: reinstall it from the Marketplace to get a compatible build.",ABI_VERSION),kind: "missing_abi_symbol".to_string(),@@ -253,7 +253,7 @@ fn load_single_plugin(if plugin_abi != ABI_VERSION {return Err(PluginLoadError {message: format!(- "ABI mismatch: plugin has v{}, core expects v{}",+ "This plugin was built for an older version of OmniGet (plugin ABI v{}, this version requires v{}). Update the plugin: reinstall it from the Marketplace to get a compatible build.",plugin_abi, ABI_VERSION),kind: "abi_mismatch".to_string(),@@ -262,6 +262,61 @@ fn load_single_plugin(});}+ // ABI_VERSION alone cannot detect a plugin compiled by a different rustc.+ // Rust has no stable ABI — trait-object vtables, fat-pointer conventions+ // and std/serde type layouts can change between compiler releases — and+ // every non-C-ABI type crossing this boundary (Box<dyn OmnigetPlugin>,+ // Arc<dyn PluginHost>, String, serde_json::Value, boxed futures) is UB on+ // a mismatch. This is exactly what crashed v0.7.1 (host: rustc 1.97.0)+ // with registry plugins built by rustc 1.95/1.96: they passed the ABI v2+ // handshake, loaded, then jumped through corrupted pointers on the first+ // plugin command (SIGSEGV on a tokio worker). Since ABI v3 the+ // export_plugin! macro also exports a build-info symbol; require it and+ // require the plugin's rustc fingerprint to match ours exactly.+ let build_info_fn: libloading::Symbol<extern "C" fn() -> *const std::os::raw::c_char> =+ unsafe { lib.get(b"omniget_plugin_build_info") }.map_err(|_| PluginLoadError {+ message: format!(+ "This plugin was built for an older version of OmniGet (missing toolchain handshake; this version requires ABI v{}). Update the plugin: reinstall it from the Marketplace to get a compatible build.",+ ABI_VERSION+ ),+ kind: "abi_mismatch".to_string(),+ plugin_abi: Some(plugin_abi),+ expected_abi: Some(ABI_VERSION),+ })?;++ // Reading a thin `*const c_char` from an extern "C" fn is FFI-safe on any+ // rustc, unlike the Rust-ABI surface it guards.+ let plugin_build_info = {+ let raw = build_info_fn();+ if raw.is_null() {+ String::new()+ } else {+ unsafe { std::ffi::CStr::from_ptr(raw) }+ .to_string_lossy()+ .into_owned()+ }+ };+ let host_info = omniget_plugin_sdk::build_info_str();+ let host_rustc = omniget_plugin_sdk::rustc_component(host_info);+ let plugin_rustc = omniget_plugin_sdk::rustc_component(&plugin_build_info);+ if plugin_rustc.is_none() || plugin_rustc != host_rustc {+ return Err(PluginLoadError {+ message: format!(+ "This plugin was built with a different Rust toolchain ('{}') than this version of OmniGet ('{}') and cannot be loaded safely. Update the plugin: reinstall it from the Marketplace to get a compatible build.",+ plugin_rustc.unwrap_or("unknown"),+ host_rustc.unwrap_or("unknown"),+ ),+ kind: "abi_mismatch".to_string(),+ plugin_abi: Some(plugin_abi),+ expected_abi: Some(ABI_VERSION),+ });+ }+ tracing::debug!(+ "[plugins] toolchain handshake ok: plugin '{}' / host '{}'",+ plugin_build_info,+ host_info+ );+let init_fn: libloading::Symbol<extern "C" fn() -> *mut dyn OmnigetPlugin> =unsafe { lib.get(b"omniget_plugin_init") }.map_err(|_| {PluginLoadError::simple("missing_init_symbol", "Missing omniget_plugin_init symbol")