Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: close release review resource leaks
[._.]/ Adam Eivy178082d28fd7
diff --git a/scripts/generate_minimax_h3_cuda.py b/scripts/generate_minimax_h3_cuda.pyindex 5a11db63b3..047f40fafd 100644--- a/scripts/generate_minimax_h3_cuda.py+++ b/scripts/generate_minimax_h3_cuda.py@@ -175,6 +175,21 @@ def validate_checkpoint_indexes(snapshot: Path) -> None:def fail_walk(error):raise error+ snapshot_abs = os.path.abspath(snapshot)+ allowed_roots = {os.path.realpath(snapshot_abs)}+ # Hugging Face snapshots normally link files into the sibling `blobs/`+ # directory. Keep that supported link shape, but do not let an arbitrary+ # symlink turn a checkpoint shard into a read of another local file.+ for ancestor in Path(snapshot_abs).parents:+ if ancestor.name == "snapshots":+ allowed_roots.add(os.path.realpath(ancestor.parent / "blobs"))++ def is_under(path, root):+ try:+ return os.path.commonpath((path, root)) == root+ except ValueError:+ return False+for folder, directories, files in os.walk(snapshot, onerror=fail_walk):# HF caches symlink FILES, not component directories. Do not silently# skip an index hidden behind a directory symlink during this walk.@@ -207,8 +222,12 @@ def validate_checkpoint_indexes(snapshot: Path) -> None:# An unused, partially cached component may lack shards. Leave# missing-file reporting to the loader, but never open a FIFO,# directory, device, or dangling symlink that DOES exist.- if os.path.lexists(target) and not os.path.isfile(target):- raise ValueError("Checkpoint shard must be a regular file.")+ if os.path.lexists(target):+ resolved_target = os.path.realpath(target)+ if not any(is_under(resolved_target, root) for root in allowed_roots):+ raise ValueError("Checkpoint shard symlink escapes the model cache.")+ if not os.path.isfile(target):+ raise ValueError("Checkpoint shard must be a regular file.")def load_pipeline(snapshot: Path, profile: str):diff --git a/scripts/generate_minimax_h3_cuda.test.js b/scripts/generate_minimax_h3_cuda.test.jsindex b3846eb91e..d410a0aa54 100644--- a/scripts/generate_minimax_h3_cuda.test.js+++ b/scripts/generate_minimax_h3_cuda.test.js@@ -69,11 +69,15 @@ describe.skipIf(!pyBin)('generate_minimax_h3_cuda.py', () => {' snapshot = Path(temp) / "snapshot"',' component = snapshot / "transformer"',' component.mkdir(parents=True)',+ ' outside = Path(temp) / "outside.safetensors"',+ ' outside.write_text("not a checkpoint")',+ ' (component / "escape.safetensors").symlink_to(outside)',' index = component / "model.safetensors.index.json"',' bad_shards = ["../outside.safetensors", "nested/../../outside.safetensors",',' str(Path(temp).absolute() / "outside.safetensors"),',' "C:/outside.safetensors", "C:outside.safetensors",',' "\\\\\\\\host\\\\share\\\\weights", "..\\\\outside.safetensors", "", None, 7, "bad\\0name"]',+ ' bad_shards.append("escape.safetensors")',' indexes = [{"weight_map": {"layer.weight": shard}} for shard in bad_shards]',' indexes += [{"layer.weight": "../outside.safetensors"}, [], {"weight_map": []}, {"weight_map": {}}]',' for profile in ("bf16", "int8-stream", "int8-lean"):',diff --git a/server/services/videoGen/conditioningMedia.js b/server/services/videoGen/conditioningMedia.jsindex d9af3273f8..a295daa5c7 100644--- a/server/services/videoGen/conditioningMedia.js+++ b/server/services/videoGen/conditioningMedia.js@@ -53,6 +53,28 @@ export async function prepareVideoConditioningMedia({);}const hasMultiKeyframes = Array.isArray(keyframes) && keyframes.length >= 2;+ if (hasMultiKeyframes) {+ // The route validates shape, but a non-route caller (test, persisted+ // queue replay, future internal API) could pass malformed entries.+ // Validate before any resize subprocess starts so a rejection cannot+ // strand temp files created for the other conditioning inputs.+ keyframes.forEach((kf, i) => {+ if (!kf || typeof kf !== 'object') {+ throw new ServerError(`keyframes[${i}] must be an object: got ${typeof kf}`, { status: 400, code: 'KEYFRAME_INVALID_SHAPE' });+ }+ if (typeof kf.path !== 'string' || !kf.path) {+ throw new ServerError(`keyframes[${i}].path must be a non-empty string`, { status: 400, code: 'KEYFRAME_INVALID_SHAPE' });+ }+ // The Python helper enforces `index` is an int; a float or numeric+ // string here would crash mid-render. Coerce + verify integerness+ // up-front so non-route callers (tests, persisted queue replays)+ // get a clear 400 instead of a Python traceback.+ const n = Number(kf.index);+ if (!Number.isInteger(n)) {+ throw new ServerError(`keyframes[${i}].index must be an integer: got ${kf.index}`, { status: 400, code: 'KEYFRAME_INVALID_SHAPE' });+ }+ });+ }const ffmpeg = (sourceImagePath || lastImageWillBeUsed || hasMultiKeyframes) ? await findFfmpeg() : null;const ffprobe = model.runtime === 'minimax_h3_ref2va' ? await findFfprobe() : null;const resizeImage = async (srcPath, tag) => {@@ -88,26 +110,6 @@ export async function prepareVideoConditioningMedia({const resizedKeyframeTempPaths = [];let resolvedKeyframes = null;if (hasMultiKeyframes) {- // The route validates shape, but a non-route caller (test, persisted- // queue replay, future internal API) could pass malformed entries.- // Fail fast with a clear error instead of letting `undefined` paths- // flow into ffmpeg or the Python helper, where the failure is opaque.- keyframes.forEach((kf, i) => {- if (!kf || typeof kf !== 'object') {- throw new ServerError(`keyframes[${i}] must be an object: got ${typeof kf}`, { status: 400, code: 'KEYFRAME_INVALID_SHAPE' });- }- if (typeof kf.path !== 'string' || !kf.path) {- throw new ServerError(`keyframes[${i}].path must be a non-empty string`, { status: 400, code: 'KEYFRAME_INVALID_SHAPE' });- }- // The Python helper enforces `index` is an int; a float or numeric- // string here would crash mid-render. Coerce + verify integerness- // up-front so non-route callers (tests, persisted queue replays)- // get a clear 400 instead of a Python traceback.- const n = Number(kf.index);- if (!Number.isInteger(n)) {- throw new ServerError(`keyframes[${i}].index must be an integer: got ${kf.index}`, { status: 400, code: 'KEYFRAME_INVALID_SHAPE' });- }- });const results = await Promise.all(keyframes.map((kf, i) => resizeImage(kf.path, `kf${i}`)));resolvedKeyframes = results.map((r, i) => {if (r.tempPath) resizedKeyframeTempPaths.push(r.tempPath);diff --git a/server/services/videoGen/conditioningMedia.test.js b/server/services/videoGen/conditioningMedia.test.jsnew file mode 100644index 0000000000..76ba80185a--- /dev/null+++ b/server/services/videoGen/conditioningMedia.test.js@@ -0,0 +1,46 @@+import { describe, expect, it, vi, beforeEach } from 'vitest';++const { execFileMock, findFfmpegMock } = vi.hoisted(() => ({+ execFileMock: vi.fn((...args) => {+ const callback = args.at(-1);+ callback(null, { stdout: '', stderr: '' });+ }),+ findFfmpegMock: vi.fn(async () => '/mock/ffmpeg'),+}));++vi.mock('../../lib/childProcess.js', async (importOriginal) => ({+ ...(await importOriginal()),+ execFile: execFileMock,+}));++vi.mock('../../lib/ffmpeg.js', async (importOriginal) => ({+ ...(await importOriginal()),+ findFfmpeg: findFfmpegMock,+}));++import { prepareVideoConditioningMedia } from './conditioningMedia.js';++describe('prepareVideoConditioningMedia', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ it('rejects malformed keyframes before resizing any other conditioning input', async () => {+ await expect(prepareVideoConditioningMedia({+ model: { runtime: 'ltx2' },+ mode: 'image',+ sourceImagePath: '/tmp/source.png',+ keyframes: [{ path: '/tmp/first.png', index: 0 }, null],+ w: 704,+ h: 448,+ parsedFps: 24,+ jobId: 'malformed-keyframes',+ uploadedTempPath: null,+ uploadedTempPaths: [],+ audioFilePath: null,+ })).rejects.toMatchObject({ status: 400, code: 'KEYFRAME_INVALID_SHAPE' });++ expect(findFfmpegMock).not.toHaveBeenCalled();+ expect(execFileMock).not.toHaveBeenCalled();+ });+});