Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

test(ffmpeg): regression-guard macOS sidecars against bad dyld paths

Louis Beaumont5c35957ba49b
diff --git a/apps/screenpipe-app-tauri/scripts/pre_build.js b/apps/screenpipe-app-tauri/scripts/pre_build.js
index 63ff1637b..f12cc8e73 100644
--- a/apps/screenpipe-app-tauri/scripts/pre_build.js
+++ b/apps/screenpipe-app-tauri/scripts/pre_build.js
@@ -311,6 +311,89 @@ async function copySystemBinary(binaryName, destination) {
console.log(`using system ${binaryName}: ${source} -> ${destination}`);
}
+// Regression guard for 9a68ae9de — static layer.
+// Inspects each macOS sidecar with `otool -L` and rejects any dylib reference
+// outside the safe-paths whitelist. Safe = `/usr/lib/`, `/System/Library/`,
+// or `@executable_path`/`@rpath`/`@loader_path` — the only locations dyld can
+// resolve on an arbitrary user's Mac. Everything else (brew's Cellar,
+// MacPorts, /Users/...) is fragile and will SIGABRT in production.
+// Covers BOTH archs since `otool` is a static analyzer.
+async function verifyMacosSidecarsSelfContained() {
+ const SAFE_PREFIXES = [
+ '/usr/lib/',
+ '/System/Library/',
+ '@executable_path',
+ '@rpath',
+ '@loader_path',
+ ];
+ const sidecars = [
+ 'ffmpeg-aarch64-apple-darwin',
+ 'ffprobe-aarch64-apple-darwin',
+ 'ffmpeg-x86_64-apple-darwin',
+ 'ffprobe-x86_64-apple-darwin',
+ ];
+ console.log('verifying macOS sidecars are self-contained...');
+ for (const bin of sidecars) {
+ if (!(await fs.exists(bin))) continue;
+ const out = await $`otool -L ${bin}`.text();
+ for (const raw of out.split('\n')) {
+ const line = raw.trim();
+ if (!line) continue;
+ // Skip the "binary:" header and "(architecture x86_64):" sub-headers for fat binaries.
+ if (line.endsWith(':')) continue;
+ const dylib = line.split(/\s+/)[0];
+ if (SAFE_PREFIXES.some((p) => dylib.startsWith(p))) continue;
+ throw new Error(
+ `sidecar ${bin} links against non-portable dylib:\n` +
+ ` ${dylib}\n` +
+ `only ${SAFE_PREFIXES.join(', ')} survive transport to a user's Mac.\n` +
+ `see commit 9a68ae9de for context.`
+ );
+ }
+ console.log(` ok: ${bin}`);
+ }
+}
+
+// Regression guard for 9a68ae9de — runtime layer.
+// Spawns the host-arch sidecar under `sandbox-exec` with brew/MacPorts paths
+// denied, then runs `-version`. dyld loads every non-weak LC_LOAD_DYLIB at
+// startup, so `-version` is enough to trip the SIGABRT v2.4.243 hit on user
+// Macs. This catches what `otool -L` can't: `dlopen`-loaded plugins and any
+// other init-time crash. Absolute dylib paths in LC_LOAD_DYLIB ignore DYLD
+// env vars, so `sandbox-exec` is the only way to actually simulate a Mac
+// without the brew rev shipped on the CI runner.
+//
+// Only checks the host-arch sidecar — the other arch gets exercised on its
+// own CI matrix entry. The static check above already covers both archs.
+async function verifyMacosSidecarsRun() {
+ const hostArch = process.arch === 'arm64' ? 'aarch64' : 'x86_64';
+ const sidecars = [
+ `ffmpeg-${hostArch}-apple-darwin`,
+ `ffprobe-${hostArch}-apple-darwin`,
+ ];
+ const profile =
+ '(version 1)' +
+ '(allow default)' +
+ '(deny file-read* (subpath "/opt/homebrew"))' +
+ '(deny file-read* (subpath "/usr/local/Cellar"))' +
+ '(deny file-read* (subpath "/opt/local"))';
+ console.log(`running ${hostArch} sidecars in a brew-less sandbox...`);
+ for (const bin of sidecars) {
+ if (!(await fs.exists(bin))) continue;
+ try {
+ await $`sandbox-exec -p ${profile} ./${bin} -version`.quiet();
+ console.log(` ok: ${bin}`);
+ } catch (err) {
+ const stderr = err.stderr?.toString?.() ?? '';
+ throw new Error(
+ `sidecar ${bin} fails to launch without /opt/homebrew, /usr/local/Cellar, /opt/local:\n` +
+ `${stderr || err.message}\n` +
+ `this is the v2.4.243 crash class — see commit 9a68ae9de.`
+ );
+ }
+ }
+}
+
async function findOnPath(binaryName) {
const pathValue = process.env.PATH || '';
for (const dir of pathValue.split(path.delimiter)) {
@@ -609,6 +692,10 @@ if (platform == 'macos') {
console.log('FFMPEG and FFPROBE checks completed');
console.log('Moved and renamed ffmpeg binary for externalBin');
+ // Runs unconditionally — cache hits get verified too.
+ await verifyMacosSidecarsSelfContained();
+ await verifyMacosSidecarsRun();
+
// Strip extended attributes from all binaries to prevent codesign failures
console.log('Stripping extended attributes from binaries...');
try {