Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

fix(export): harden native release gates

wiiiii123ae40a13e85c4
diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.ts
index f8d02709..5836b3e4 100644
--- a/electron/electron-env.d.ts
+++ b/electron/electron-env.d.ts
@@ -301,6 +301,13 @@ interface Window {
size: number;
elapsedMs: number;
deltaMs: number | null;
+ recordedElapsedMs?: number;
+ recordedDeltaMs?: number | null;
+ }>;
+ pauseIntervals?: Array<{
+ startElapsedMs: number;
+ endElapsedMs?: number;
+ durationMs?: number;
}>;
},
) => Promise<{ success: boolean; path?: string; error?: string }>;
diff --git a/electron/ipc/register/export.ts b/electron/ipc/register/export.ts
index 8ff7199b..a977ee74 100644
--- a/electron/ipc/register/export.ts
+++ b/electron/ipc/register/export.ts
@@ -42,6 +42,7 @@ import {
type NativeExportEncodingMode,
type NativeVideoExportFinishOptions,
} from "../nativeVideoExport";
+import { isAllowedLocalReadPath, resolveApprovedLocalMediaPath } from "../project/manager";
import { approveUserPath } from "../utils";
function getPartialExportDestinationPath(destinationPath: string) {
@@ -74,8 +75,32 @@ export async function moveExportedTempFile(tempPath: string, destinationPath: st
if (code !== "EEXIST" && code !== "EPERM") {
throw renameError;
}
- await fs.rm(destinationPath, { force: true });
- await fs.rename(partialDestinationPath, destinationPath);
+
+ const backupDestinationPath = getPartialExportDestinationPath(destinationPath);
+ let movedExistingDestination = false;
+ try {
+ await fs.rename(destinationPath, backupDestinationPath);
+ movedExistingDestination = true;
+ } catch (backupError) {
+ if ((backupError as NodeJS.ErrnoException).code !== "ENOENT") {
+ throw backupError;
+ }
+ }
+
+ try {
+ await fs.rename(partialDestinationPath, destinationPath);
+ } catch (replaceError) {
+ if (movedExistingDestination) {
+ await fs
+ .rename(backupDestinationPath, destinationPath)
+ .catch(() => undefined);
+ }
+ throw replaceError;
+ }
+
+ if (movedExistingDestination) {
+ await fs.rm(backupDestinationPath, { force: true });
+ }
}
try {
await fs.rm(tempPath, { force: true });
@@ -94,6 +119,98 @@ export async function moveExportedTempFile(tempPath: string, destinationPath: st
}
}
+async function resolveAllowedReadableFilePath(
+ filePath: string,
+ label: string,
+ options: { mediaOnly?: boolean } = {},
+) {
+ if (typeof filePath !== "string" || filePath.trim().length === 0) {
+ throw new Error(`${label} requires a file path`);
+ }
+
+ if (options.mediaOnly ?? true) {
+ const resolvedMediaPath = await resolveApprovedLocalMediaPath(filePath);
+ if (!resolvedMediaPath) {
+ throw new Error(`${label} is not an approved readable media file`);
+ }
+
+ return resolvedMediaPath;
+ }
+
+ const resolvedPath = path.resolve(filePath);
+ const realPath = await fs.realpath(resolvedPath).catch(() => null);
+ if (!realPath) {
+ throw new Error(`${label} does not exist`);
+ }
+
+ const stat = await fs.stat(realPath).catch(() => null);
+ if (!stat?.isFile()) {
+ throw new Error(`${label} is not a readable file`);
+ }
+
+ if (!isAllowedLocalReadPath(realPath)) {
+ throw new Error(`${label} is not approved for local reads`);
+ }
+
+ return realPath;
+}
+
+async function sanitizeNativeStaticLayoutExportOptions(
+ options: NativeStaticLayoutExportOptions,
+): Promise<NativeStaticLayoutExportOptions> {
+ const sanitized: NativeStaticLayoutExportOptions = {
+ ...options,
+ inputPath: await resolveAllowedReadableFilePath(options.inputPath, "Native input"),
+ };
+ const mutableOptions = sanitized as unknown as Record<string, unknown>;
+
+ for (const [field, label] of [
+ ["backgroundImagePath", "Native background image"],
+ ["webcamInputPath", "Native webcam input"],
+ ["cursorAtlasPath", "Native cursor atlas"],
+ ] as const) {
+ const value = mutableOptions[field];
+ if (typeof value === "string" && value.trim().length > 0) {
+ mutableOptions[field] = await resolveAllowedReadableFilePath(value, label);
+ } else if (value === "" || value === undefined) {
+ mutableOptions[field] = null;
+ } else if (value !== null) {
+ throw new Error(`${label} must be a file path`);
+ }
+ }
+
+ for (const [field, label] of [
+ ["cursorTelemetryPath", "Native cursor telemetry"],
+ ["cursorAtlasMetadataPath", "Native cursor atlas metadata"],
+ ["zoomTelemetryPath", "Native zoom telemetry"],
+ ["timelineMapPath", "Native timeline map"],
+ ] as const) {
+ const value = mutableOptions[field];
+ if (typeof value === "string" && value.trim().length > 0) {
+ mutableOptions[field] = await resolveAllowedReadableFilePath(value, label, {
+ mediaOnly: false,
+ });
+ } else if (value === "" || value === undefined) {
+ mutableOptions[field] = null;
+ } else if (value !== null) {
+ throw new Error(`${label} must be a file path`);
+ }
+ }
+
+ const audioOptions = sanitized.audioOptions;
+ if (audioOptions?.audioSourcePath) {
+ sanitized.audioOptions = {
+ ...audioOptions,
+ audioSourcePath: await resolveAllowedReadableFilePath(
+ audioOptions.audioSourcePath,
+ "Native audio source",
+ ),
+ };
+ }
+
+ return sanitized;
+}
+
function isTempPathSafe(tempPath: string): boolean {
const tempRoot = path.resolve(app.getPath("temp"));
const candidate = path.resolve(tempPath);
@@ -251,7 +368,14 @@ export function registerExportHandlers() {
throw new Error("Native metadata probe requires a file path");
}
- const metadata = await probeNativeVideoMetadata(getFfmpegBinaryPath(), filePath);
+ const resolvedFilePath = await resolveAllowedReadableFilePath(
+ filePath,
+ "Native metadata probe",
+ );
+ const metadata = await probeNativeVideoMetadata(
+ getFfmpegBinaryPath(),
+ resolvedFilePath,
+ );
return {
success: true,
metadata,
@@ -272,10 +396,11 @@ export function registerExportHandlers() {
if (!options || typeof options.inputPath !== "string") {
throw new Error("Native static layout export requires an input path");
}
+ const sanitizedOptions = await sanitizeNativeStaticLayoutExportOptions(options);
const result = await exportNativeStaticLayoutVideo(
getFfmpegBinaryPath(),
- options,
+ sanitizedOptions,
(progress) => {
if (event.sender.isDestroyed()) {
return;
diff --git a/electron/ipc/register/recording.ts b/electron/ipc/register/recording.ts
index 9321f5b8..69ed08cb 100644
--- a/electron/ipc/register/recording.ts
+++ b/electron/ipc/register/recording.ts
@@ -206,8 +206,14 @@ function pickMicrophoneChunkEvents(value: unknown): MicrophoneChunkTimingEvent[]
const { index, size, elapsedMs, deltaMs, recordedElapsedMs, recordedDeltaMs } = event;
if (
typeof index !== "number" ||
+ !Number.isFinite(index) ||
+ index < 0 ||
typeof size !== "number" ||
- typeof elapsedMs !== "number"
+ !Number.isFinite(size) ||
+ size < 0 ||
+ typeof elapsedMs !== "number" ||
+ !Number.isFinite(elapsedMs) ||
+ elapsedMs < 0
) {
return null;
}
@@ -216,7 +222,10 @@ function pickMicrophoneChunkEvents(value: unknown): MicrophoneChunkTimingEvent[]
index: Math.round(index),
size: Math.round(size),
elapsedMs: Math.round(elapsedMs),
- deltaMs: typeof deltaMs === "number" ? Math.round(deltaMs) : null,
+ deltaMs:
+ typeof deltaMs === "number" && Number.isFinite(deltaMs)
+ ? Math.max(0, Math.round(deltaMs))
+ : null,
...(typeof recordedElapsedMs === "number" &&
Number.isFinite(recordedElapsedMs) &&
recordedElapsedMs >= 0
@@ -240,7 +249,12 @@ function pickMicrophonePauseIntervals(value: unknown): MicrophonePauseInterval[]
const intervals = value
.map((interval) => {
- if (!isRecord(interval) || typeof interval.startElapsedMs !== "number") {
+ if (
+ !isRecord(interval) ||
+ typeof interval.startElapsedMs !== "number" ||
+ !Number.isFinite(interval.startElapsedMs) ||
+ interval.startElapsedMs < 0
+ ) {
return null;
}
diff --git a/electron/native/nvidia-cuda-compositor/render-tahoe-cursor-atlas.cjs b/electron/native/nvidia-cuda-compositor/render-tahoe-cursor-atlas.cjs
index 233ed252..5407d327 100644
--- a/electron/native/nvidia-cuda-compositor/render-tahoe-cursor-atlas.cjs
+++ b/electron/native/nvidia-cuda-compositor/render-tahoe-cursor-atlas.cjs
@@ -1,5 +1,4 @@
const { app, BrowserWindow, ipcMain } = require("electron");
-const fs = require("node:fs");
const path = require("node:path");
const drawHeight = 256;
diff --git a/electron/native/nvidia-cuda-compositor/run-mp4-pipeline.mjs b/electron/native/nvidia-cuda-compositor/run-mp4-pipeline.mjs
index d71146c9..d1443497 100644
--- a/electron/native/nvidia-cuda-compositor/run-mp4-pipeline.mjs
+++ b/electron/native/nvidia-cuda-compositor/run-mp4-pipeline.mjs
@@ -1460,12 +1460,13 @@ const mux = skipMux
},
);
+const finalOutputPath = skipMux ? encodedPath : outputPath;
const outputInfo = skipMux
? { streams: [] }
: ffprobeJson([
"-show_entries",
"stream=index,codec_type,codec_name,width,height,duration,avg_frame_rate,nb_frames",
- outputPath,
+ finalOutputPath,
]);
const outputStreams = outputInfo.streams ?? [];
const outputVideo = outputStreams.find((stream) => stream.codec_type === "video") ?? null;
@@ -1476,7 +1477,9 @@ console.log(
{
success: true,
inputPath,
- outputPath,
+ outputPath: finalOutputPath,
+ requestedOutputPath: outputPath,
+ encodedPath,
fps,
bitrateMbps,
encodingMode,
diff --git a/scripts/benchmark-export-queues.mjs b/scripts/benchmark-export-queues.mjs
index 7344ebe2..6628b9d8 100644
--- a/scripts/benchmark-export-queues.mjs
+++ b/scripts/benchmark-export-queues.mjs
@@ -890,8 +890,14 @@ async function main() {
const benchmarkRequests = buildBenchmarkRequests();
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "recordly-export-queue-bench-"));
- const inputPath = path.join(tempDir, "input.mp4");
- const webcamInputPath = useWebcamOverlay ? path.join(tempDir, "webcam.mp4") : null;
+ const inputExtension = providedInputPath ? path.extname(providedInputPath) || ".mp4" : ".mp4";
+ const inputPath = path.join(tempDir, `input${inputExtension}`);
+ const webcamExtension = providedWebcamInputPath
+ ? path.extname(providedWebcamInputPath) || ".mp4"
+ : ".mp4";
+ const webcamInputPath = useWebcamOverlay
+ ? path.join(tempDir, `webcam${webcamExtension}`)
+ : null;
try {
console.log("[benchmark-export-queues] Config");
diff --git a/scripts/build-windows-gpu-export.mjs b/scripts/build-windows-gpu-export.mjs
index d981bfa6..2bc64830 100644
--- a/scripts/build-windows-gpu-export.mjs
+++ b/scripts/build-windows-gpu-export.mjs
@@ -93,7 +93,8 @@ if (!cmake) {
binaryName: "recordly-gpu-export.exe",
});
if (!verification.ok) {
- console.warn(formatNativeHelperManifestWarning("build-windows-gpu-export", verification));
+ console.error(formatNativeHelperManifestWarning("build-windows-gpu-export", verification));
+ process.exit(1);
}
console.log(`[build-windows-gpu-export] Using bundled helper: ${bundledExePath}`);
process.exit(0);
diff --git a/scripts/normalize-electron-main-cjs.mjs b/scripts/normalize-electron-main-cjs.mjs
index 4e85495a..3d3b186c 100644
--- a/scripts/normalize-electron-main-cjs.mjs
+++ b/scripts/normalize-electron-main-cjs.mjs
@@ -112,6 +112,184 @@ function updateLexicalState(line, state) {
return { mode };
}
+function hasTokenBoundary(line, startIndex, endIndex) {
+ const before = line[startIndex - 1];
+ const after = line[endIndex];
+ const isIdentifier = (char) => Boolean(char && /[A-Za-z0-9_$]/.test(char));
+ return !isIdentifier(before) && !isIdentifier(after);
+}
+
+function replaceImportMetaUrlInCode(line, state) {
+ const token = "import.meta.url";
+ let mode = state.mode;
+ let escaped = false;
+ let changed = false;
+ let normalizedLine = "";
+
+ for (let index = 0; index < line.length; index += 1) {
+ const char = line[index];
+ const next = line[index + 1];
+
+ if (mode === "block-comment") {
+ normalizedLine += char;
+ if (char === "*" && next === "/") {
+ normalizedLine += next;
+ mode = null;
+ index += 1;
+ }
+ continue;
+ }
+
+ if (mode === "single-quote" || mode === "double-quote" || mode === "template") {
+ normalizedLine += char;
+ if (escaped) {
+ escaped = false;
+ continue;
+ }
+
+ if (char === "\\") {
+ escaped = true;
+ continue;
+ }
+
+ if (
+ (mode === "single-quote" && char === "'") ||
+ (mode === "double-quote" && char === '"') ||
+ (mode === "template" && char === "`")
+ ) {
+ mode = null;
+ }
+ continue;
+ }
+
+ if (char === "/" && next === "/") {
+ normalizedLine += line.slice(index);
+ break;
+ }
+
+ if (char === "/" && next === "*") {
+ normalizedLine += char + next;
+ mode = "block-comment";
+ index += 1;
+ continue;
+ }
+
+ if (char === "'") {
+ normalizedLine += char;
+ mode = "single-quote";
+ continue;
+ }
+
+ if (char === '"') {
+ normalizedLine += char;
+ mode = "double-quote";
+ continue;
+ }
+
+ if (char === "`") {
+ normalizedLine += char;
+ mode = "template";
+ continue;
+ }
+
+ if (
+ line.startsWith(token, index) &&
+ hasTokenBoundary(line, index, index + token.length)
+ ) {
+ normalizedLine += IMPORT_META_URL_CJS_REPLACEMENT;
+ changed = true;
+ index += token.length - 1;
+ continue;
+ }
+
+ normalizedLine += char;
+ }
+
+ if (mode === "single-quote" || mode === "double-quote") {
+ mode = null;
+ }
+
+ return {
+ line: normalizedLine,
+ state: { mode },
+ changed,
+ };
+}
+
+function containsImportMetaInCode(line, state) {
+ const token = "import.meta";
+ let mode = state.mode;
+ let escaped = false;
+
+ for (let index = 0; index < line.length; index += 1) {
+ const char = line[index];
+ const next = line[index + 1];
+
+ if (mode === "block-comment") {
+ if (char === "*" && next === "/") {
+ mode = null;
+ index += 1;
+ }
+ continue;
+ }
+
+ if (mode === "single-quote" || mode === "double-quote" || mode === "template") {
+ if (escaped) {
+ escaped = false;
+ continue;
+ }
+
+ if (char === "\\") {
+ escaped = true;
+ continue;
+ }
+
+ if (
+ (mode === "single-quote" && char === "'") ||
+ (mode === "double-quote" && char === '"') ||
+ (mode === "template" && char === "`")
+ ) {
+ mode = null;
+ }
+ continue;
+ }
+
+ if (char === "/" && next === "/") {
+ break;
+ }
+
+ if (char === "/" && next === "*") {
+ mode = "block-comment";
+ index += 1;
+ continue;
+ }
+
+ if (char === "'") {
+ mode = "single-quote";
+ continue;
+ }
+
+ if (char === '"') {
+ mode = "double-quote";
+ continue;
+ }
+
+ if (char === "`") {
+ mode = "template";
+ continue;
+ }
+
+ if (
+ line.startsWith(token, index) &&
+ hasTokenBoundary(line, index, index + token.length)
+ ) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
export function normalizeElectronMainCjsSource(source) {
let changed = false;
const lineBreak = source.includes("\r\n") ? "\r\n" : "\n";
@@ -129,16 +307,13 @@ export function normalizeElectronMainCjsSource(source) {
}
}
- const normalizedLine = line.replace(
- /\bimport\.meta\.url\b/g,
- IMPORT_META_URL_CJS_REPLACEMENT,
- );
- if (normalizedLine !== line) {
+ const normalized = replaceImportMetaUrlInCode(line, state);
+ if (normalized.changed) {
changed = true;
}
- normalizedLines.push(normalizedLine);
- state = updateLexicalState(normalizedLine, state);
+ normalizedLines.push(normalized.line);
+ state = normalized.state;
}
if (!changed) {
@@ -166,7 +341,7 @@ export function findElectronMainCjsEsmSyntax(source) {
});
continue;
}
- if (/\bimport\.meta\b/.test(line)) {
+ if (containsImportMetaInCode(line, state)) {
matches.push({
line: index + 1,
text: line.trim(),
diff --git a/scripts/smoke-packaged-binaries.mjs b/scripts/smoke-packaged-binaries.mjs
index 97e5eb65..eeb01c17 100644
--- a/scripts/smoke-packaged-binaries.mjs
+++ b/scripts/smoke-packaged-binaries.mjs
@@ -159,7 +159,7 @@ function getRequiredArchTags() {
function getExpectedNativeHelperFiles(archTag) {
if (archTag.startsWith("win32-")) {
- return [
+ const helpers = [
{ name: "wgc-capture.exe", label: "Windows capture helper", executable: true },
{
name: "cursor-monitor.exe",
@@ -171,15 +171,18 @@ function getExpectedNativeHelperFiles(archTag) {
label: "Windows GPU export helper",
executable: true,
},
- {
- name: "recordly-nvidia-cuda-compositor.exe",
- label: "NVIDIA CUDA compositor helper",
- executable: true,
- },
{ name: "helpers-manifest.json", label: "Windows helper manifest" },
{ name: "whisper-cli.exe", label: "Whisper CLI runtime", executable: true },
{ name: "whisper-runtime.json", label: "Whisper runtime manifest" },
];
+ if (archTag === "win32-x64") {
+ helpers.push({
+ name: "recordly-nvidia-cuda-compositor.exe",
+ label: "NVIDIA CUDA compositor helper",
+ executable: true,
+ });
+ }
+ return helpers;
}
if (archTag.startsWith("darwin-")) {
diff --git a/src/components/video-editor/VideoPlayback.tsx b/src/components/video-editor/VideoPlayback.tsx
index d2d65cb6..8ec9831f 100644
--- a/src/components/video-editor/VideoPlayback.tsx
+++ b/src/components/video-editor/VideoPlayback.tsx
@@ -1248,6 +1248,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
}
if (suspendRendering) {
+ app.ticker.stop();
bgVideoRef.current?.pause();
webcamVideoRef.current?.pause();
layoutVideoContentRef.current?.();
diff --git a/src/lib/assetPath.test.ts b/src/lib/assetPath.test.ts
index 7cb51728..0cf6cd06 100644
--- a/src/lib/assetPath.test.ts
+++ b/src/lib/assetPath.test.ts
@@ -1,5 +1,27 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
-import { getExportableVideoUrl, getRenderableVideoUrl } from "./assetPath";
+import { getExportableVideoUrl, getRenderableAssetUrl, getRenderableVideoUrl } from "./assetPath";
+
+describe("getRenderableAssetUrl", () => {
+ beforeEach(() => {
+ vi.unstubAllGlobals();
+ });
+
+ it("keeps absolute POSIX image paths on the local-file path", async () => {
+ const readLocalFile = vi.fn(async () => ({
+ success: false,
+ }));
+ vi.stubGlobal("window", {
+ electronAPI: {
+ readLocalFile,
+ },
+ });
+
+ await expect(getRenderableAssetUrl("/Users/egg/Desktop/bg.jpg")).resolves.toBe(
+ "file:///Users/egg/Desktop/bg.jpg",
+ );
+ expect(readLocalFile).toHaveBeenCalledWith("/Users/egg/Desktop/bg.jpg");
+ });
+});
describe("getRenderableVideoUrl", () => {
beforeEach(() => {
diff --git a/src/lib/assetPath.ts b/src/lib/assetPath.ts
index 86a92026..d6acbfbc 100644
--- a/src/lib/assetPath.ts
+++ b/src/lib/assetPath.ts
@@ -136,9 +136,11 @@ export async function getRenderableAssetUrl(asset: string): Promise<string> {
const availableAsset = await resolveAvailableWallpaperPath(asset);
const resolvedAsset =
- availableAsset.startsWith("/") && !availableAsset.startsWith("//")
- ? await getAssetPath(availableAsset.replace(/^\//, ""))
- : availableAsset;
+ isAbsoluteLocalAssetPath(availableAsset) && !isBundledAssetPath(availableAsset)
+ ? toFileUrl(availableAsset)
+ : isBundledAssetPath(availableAsset)
+ ? await getAssetPath(availableAsset.replace(/^\//, ""))
+ : availableAsset;
const localFilePath = toLocalFilePath(resolvedAsset);
if (!localFilePath || typeof window === "undefined" || !window.electronAPI?.readLocalFile) {
diff --git a/src/lib/exporter/nativeStaticLayoutTelemetry.ts b/src/lib/exporter/nativeStaticLayoutTelemetry.ts
index 6c45246e..182bb06e 100644
--- a/src/lib/exporter/nativeStaticLayoutTelemetry.ts
+++ b/src/lib/exporter/nativeStaticLayoutTelemetry.ts
@@ -151,7 +151,7 @@ function findLatestStableCursorType(
return sample.cursorType;
}
- return samples[lo]?.cursorType ?? "arrow";
+ return "arrow";
}
function getCursorTypeIndex(cursorType: string | undefined) {
diff --git a/src/lib/wallpapers.test.ts b/src/lib/wallpapers.test.ts
index 57100955..62d923e3 100644
--- a/src/lib/wallpapers.test.ts
+++ b/src/lib/wallpapers.test.ts
@@ -70,6 +70,21 @@ describe("wallpapers", () => {
);
});
+ it("strips query strings and fragments before checking bundled wallpaper files", async () => {
+ vi.stubGlobal("window", {
+ electronAPI: {
+ listAssetDirectory: vi.fn().mockResolvedValue({
+ success: true,
+ files: ["wispysky.mp4"],
+ }),
+ },
+ });
+
+ await expect(resolveAvailableWallpaperPath("/wallpapers/wispysky.mp4#t=0.1")).resolves.toBe(
+ "/wallpapers/wispysky.mp4#t=0.1",
+ );
+ });
+
it("preserves non-bundled wallpaper values", async () => {
await expect(resolveAvailableWallpaperPath("#123456")).resolves.toBe("#123456");
await expect(resolveAvailableWallpaperPath("data:image/png;base64,abc")).resolves.toBe(
diff --git a/src/lib/wallpapers.ts b/src/lib/wallpapers.ts
index 2cdd8a79..1bddc410 100644
--- a/src/lib/wallpapers.ts
+++ b/src/lib/wallpapers.ts
@@ -56,7 +56,7 @@ function getBundledWallpaperFileName(value: string) {
return null;
}
- const normalizedValue = value.split("?")[0] ?? value;
+ const normalizedValue = value.split(/[?#]/)[0] ?? value;
const fileName = normalizedValue.split("/").filter(Boolean).pop();
return fileName ? safeDecodeFileName(fileName) : null;
}