The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix: validate bundled Windows archives and preserve load failures
Steven Enamakel5ffb9eb2ad76
diff --git a/.github/workflows/windows-module-bundle.yml b/.github/workflows/windows-module-bundle.ymlindex 19d7688eae..3168f79b65 100644--- a/.github/workflows/windows-module-bundle.yml+++ b/.github/workflows/windows-module-bundle.yml@@ -21,8 +21,8 @@ jobs:runs-on: windows-latesttimeout-minutes: 30steps:- - uses: actions/checkout@v7- - uses: actions/setup-node@v6+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7+ - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6with:node-version: 24.x- name: Check registry coveragediff --git a/crates/openhuman-core/src/modules/ops.rs b/crates/openhuman-core/src/modules/ops.rsindex 2f7f8dac89..834707519c 100644--- a/crates/openhuman-core/src/modules/ops.rs+++ b/crates/openhuman-core/src/modules/ops.rs@@ -237,25 +237,22 @@ async fn resolve(config: &Config, record: &'static ModuleRecord) -> Result<(), Slet allow_download = config.modules.allow_download;let module_config = module_config(config, record.id);let cache_root = root.clone();- let outcome =- blocking(move || load_cached(runtime, record, &cache_root, module_config, allow_download))- .await;+ let outcome = blocking(move || {+ load_cached(+ runtime,+ record,+ &cache_root,+ module_config,+ allow_download,+ BUNDLED_RELEASES.get().map(PathBuf::as_path),+ )+ })+ .await;match outcome {Ok(()) => {prune_stale_versions(&root, record);Ok(())}- Err(reason) if !allow_download => {- log::debug!(- "[modules] '{}' release cache miss with downloads disabled: {reason}",- record.id- );- Err(format!(- "module '{}' is unavailable: no local artifact is installed and downloads are \- disabled in configuration",- record.id- ))- }Err(reason) => Err(reason),}}@@ -293,6 +290,7 @@ fn load_cached(install_root: &Path,module_config: serde_json::Value,allow_download: bool,+ bundled_root: Option<&Path>,) -> Result<(), String> {let candidates = platform::host_candidates();let assets: Vec<_> = candidates@@ -309,7 +307,7 @@ fn load_cached(let mut last_error = String::new();let mut found_bundled = false;- if let Some(bundled_root) = BUNDLED_RELEASES.get() {+ if let Some(bundled_root) = bundled_root {for asset in &assets {let Some(cache_dir) = artifact_dir(bundled_root, record, asset.host_key) else {continue;@@ -389,6 +387,17 @@ fn load_cached(}}}+ if !allow_download {+ log::debug!(+ "[modules] '{}' release cache miss with downloads disabled: {last_error}",+ record.id+ );+ return Err(format!(+ "module '{}' is unavailable: no local artifact is installed and downloads are \+ disabled in configuration",+ record.id+ ));+ }Err(format!("module '{}' could not be loaded: {last_error}. This is terminal for the running \process; restart the app to try again",diff --git a/crates/openhuman-core/src/modules/ops_tests.rs b/crates/openhuman-core/src/modules/ops_tests.rsindex 811dceec1f..5670bea174 100644--- a/crates/openhuman-core/src/modules/ops_tests.rs+++ b/crates/openhuman-core/src/modules/ops_tests.rs@@ -10,6 +10,77 @@ use crate::modules::ops::{self, install_dir, list};use crate::modules::registry;use crate::modules::types::ModuleState;+fn test_bundled_record() -> &'static crate::modules::types::ModuleRecord {+ use crate::modules::types::{LoadPolicy, ModuleRecord, PlatformAsset};++ let host_key = Box::leak(+ crate::modules::platform::host_candidates()[0]+ .clone()+ .into_boxed_str(),+ );+ let assets = Box::leak(Box::new([PlatformAsset {+ host_key,+ archive: "test-bundled-module.zip",+ // SHA-256 of the empty archive staged by the test.+ sha256: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",+ }]));+ Box::leak(Box::new(ModuleRecord {+ id: "test-bundled-module",+ description: "test module",+ bus_name: "test.BundledModule",+ object_path: "/test/BundledModule",+ version: "0.0.0",+ release_url: "https://github.com/tinyhumansai/tinydocs/releases/tag/v0.1.16",+ assets,+ load: LoadPolicy::Lazy,+ }))+}++#[tokio::test]+async fn invalid_installer_bundle_is_reported_without_falling_back_to_the_cache() {+ let record = test_bundled_record();+ let bundled = tempfile::tempdir().unwrap();+ let user_cache = tempfile::tempdir().unwrap();+ let bundle_dir = ops::artifact_dir(bundled.path(), record, record.assets[0].host_key).unwrap();+ std::fs::create_dir_all(&bundle_dir).unwrap();+ std::fs::write(bundle_dir.join(record.assets[0].archive), b"").unwrap();++ let runtime = crate::modules::host::runtime().await.unwrap();+ let error = ops::load_cached(+ runtime,+ record,+ user_cache.path(),+ serde_json::json!({}),+ false,+ Some(bundled.path()),+ )+ .unwrap_err();++ assert!(error.contains("installer bundle"), "{error}");+ assert!(error.contains("repairing the installation"), "{error}");+ assert!(!user_cache.path().join(record.id).exists());+}++#[tokio::test]+async fn absent_installer_bundle_uses_the_existing_cache_miss_path() {+ let record = test_bundled_record();+ let bundled = tempfile::tempdir().unwrap();+ let user_cache = tempfile::tempdir().unwrap();+ let runtime = crate::modules::host::runtime().await.unwrap();+ let error = ops::load_cached(+ runtime,+ record,+ user_cache.path(),+ serde_json::json!({}),+ false,+ Some(bundled.path()),+ )+ .unwrap_err();++ assert!(error.contains("downloads are disabled"), "{error}");+ assert!(!error.contains("installer bundle"), "{error}");+}+/// A config with modules on but downloads off, so nothing reaches the network.fn offline_config() -> Config {let mut config = Config::default();diff --git a/scripts/__tests__/stage-windows-modules.test.mjs b/scripts/__tests__/stage-windows-modules.test.mjsindex 93ec166512..a1508868aa 100644--- a/scripts/__tests__/stage-windows-modules.test.mjs+++ b/scripts/__tests__/stage-windows-modules.test.mjs@@ -1,9 +1,12 @@import assert from "node:assert/strict";+import { mkdtempSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";import { test } from "node:test";import { readRegistrySource } from "../ci/self-hosted/test-module-assets.mjs";import { parseAllList } from "../lib/module-pins.mjs";-import { bundledAssets } from "../release/stage-windows-modules.mjs";+import { bundledAssets, extractWindowsZip } from "../release/stage-windows-modules.mjs";test("every compiled module has one pinned Windows installer asset", () => {const source = readRegistrySource();@@ -25,3 +28,35 @@ test("a missing Windows pin fails staging before any download", () => {);assert.throws(() => bundledAssets(source), /has no windows-2022-x86_64 asset/);});++test("Windows extraction rejects an archive entry escaping its destination", {+ skip: process.platform !== "win32",+}, () => {+ const root = mkdtempSync(join(tmpdir(), "openhuman-zip-boundary-"));+ const destination = join(root, "modules");+ mkdirSync(destination);+ const archive = join(root, "escape.zip");+ const name = Buffer.from("../escape.txt");+ const local = Buffer.alloc(30);+ local.writeUInt32LE(0x04034b50, 0);+ local.writeUInt16LE(20, 4);+ local.writeUInt16LE(name.length, 26);+ const central = Buffer.alloc(46);+ central.writeUInt32LE(0x02014b50, 0);+ central.writeUInt16LE(20, 4);+ central.writeUInt16LE(20, 6);+ central.writeUInt16LE(name.length, 28);+ const end = Buffer.alloc(22);+ end.writeUInt32LE(0x06054b50, 0);+ end.writeUInt16LE(1, 8);+ end.writeUInt16LE(1, 10);+ end.writeUInt32LE(central.length + name.length, 12);+ end.writeUInt32LE(local.length + name.length, 16);+ writeFileSync(archive, Buffer.concat([local, name, central, name, end]));++ assert.throws(+ () => extractWindowsZip(archive, destination),+ (error) => /outside/i.test(error.stderr?.toString() ?? ""),+ );+ assert.throws(() => readFileSync(join(root, "escape.txt")), { code: "ENOENT" });+});diff --git a/scripts/release/stage-windows-modules.mjs b/scripts/release/stage-windows-modules.mjsindex a3d8125819..36da8cf4ef 100644--- a/scripts/release/stage-windows-modules.mjs+++ b/scripts/release/stage-windows-modules.mjs@@ -50,6 +50,28 @@ function dllsUnder(dir) {});}+export function extractWindowsZip(archive, dir) {+ // ZipFile.ExtractToDirectory rejects entries that escape the destination.+ // It also avoids Git Bash's tar.exe, which may not understand drive paths.+ execFileSync(+ "powershell.exe",+ [+ "-NoProfile",+ "-NonInteractive",+ "-Command",+ "$ErrorActionPreference = 'Stop'; try { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory($env:OPENHUMAN_MODULE_ARCHIVE, $env:OPENHUMAN_MODULE_DESTINATION) } catch { [Console]::Error.WriteLine($_.Exception.Message); exit 1 }",+ ],+ {+ env: {+ ...process.env,+ OPENHUMAN_MODULE_ARCHIVE: archive,+ OPENHUMAN_MODULE_DESTINATION: dir,+ },+ stdio: "pipe",+ },+ );+}+export function stageWindowsModules(output = OUTPUT) {if (process.platform !== "win32") {throw new Error("stage-windows-modules must run on a Windows build runner");@@ -69,7 +91,7 @@ export function stageWindowsModules(output = OUTPUT) {if (actual !== asset.sha256.toLowerCase()) {throw new Error(`${asset.id}: downloaded archive does not match the compiled registry pin`);}- execFileSync("tar.exe", ["-xf", archive, "-C", dir], { stdio: "inherit" });+ extractWindowsZip(archive, dir);if (dllsUnder(dir).length !== 1) {throw new Error(`${asset.id}: expected exactly one DLL in the release archive`);}