Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 3d0192ed43543122a7a9767a10e7a78c3dacf670
parent 808e994b30b1024b7570c23b8a3304c884df0fcf
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 12 Nov 2026 08:11:51 -0500

local media: a short-form stamp too long to be a number is not a cue, and a recording whose name a reference cannot hold is held in the preview

vtt: SHORT_CUE_TIMING_RE's hours are unbounded digits, so a 400-digit hour
read as Infinity and reached cue JSON as null. Only the short reading can
produce one (the hh:mm:ss.mmm line has two hour digits); such a line is now not
a cue line. Pinned, with a linear-time check over hostile timing lines.

scan: a media name holding a control character, \ or : was offered as "new"
and then refused at import by coerceExternalMediaReference ("Import refused;
rescan and check source/channel availability"). The scan asks the same rule
(isExternalMediaRelativePath, now shared by both) and holds the row as an issue
that says why, with no fingerprint, preparation or transcription token.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/lib/localMedia.ts | 18++++++++++++------
Mcommon/lib/localMediaScan.test.ts | 18++++++++++++++++++
Mcommon/lib/localMediaScan.ts | 11+++++++++--
Mcommon/lib/vtt.test.ts | 20++++++++++++++++++++
Mcommon/lib/vtt.ts | 3+++
5 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/common/lib/localMedia.ts b/common/lib/localMedia.ts @@ -32,16 +32,22 @@ export function coerceLocalMediaConfig(value: unknown): LocalMediaConfig | undef return { sourceId: value.sourceId, directory, ...(value.playback === true ? { playback: true as const } : {}) }; } +// Whether a library-relative path can be stored in a reference. Literal +// filenames with '/' separators, never URL-decoded; both OSes' escape syntax +// (\ and :) and control characters are refused regardless of the machine doing +// the read. No path normalization: it would conceal traversal or change a +// source name. The scan asks this too, so a recording whose name a reference +// cannot hold is an issue in its preview, not a failed import. +export function isExternalMediaRelativePath(relativePath: string): boolean { + return !!relativePath && relativePath.length <= 4096 && !/[\\:\x00-\x1f\x7f]/.test(relativePath) + && !relativePath.split("/").some((part) => !part || part === "." || part === "..") + && /\.mp4$/i.test(relativePath); +} export function coerceExternalMediaReference(value: unknown): ExternalMediaReference | null { if (!record(value) || value.version !== 1 || value.kind !== "external" || !isLocalMediaSourceId(value.sourceId) || typeof value.relativePath !== "string") return null; const relativePath = value.relativePath; - // Store literal filenames using '/' separators, never URL-decode them. - // Reject both OSes' escape syntax regardless of the machine doing the read. - // No path normalization: it would conceal traversal or change a source name. - if (!relativePath || relativePath.length > 4096 || /[\\:\x00-\x1f\x7f]/.test(relativePath) - || relativePath.split("/").some((part) => !part || part === "." || part === "..") - || !/\.mp4$/i.test(relativePath)) return null; + if (!isExternalMediaRelativePath(relativePath)) return null; return { version: 1, kind: "external", sourceId: value.sourceId, relativePath }; } diff --git a/common/lib/localMediaScan.test.ts b/common/lib/localMediaScan.test.ts @@ -169,3 +169,21 @@ test("isolated zero-duration cues warn without changing source; all-point transc assert.match(result.candidates[1].issues.join(), /no positive-duration/); assert.equal(await readFile(path.join(root, "mixed.vtt"), "utf8"), mixed); }); +// A name a library reference cannot hold (coerceExternalMediaReference refuses +// a control character, \ or :) is an issue in the preview: offered as new, its +// import could only fail. No fingerprint of any kind is offered for it. +test("a recording whose file name a reference cannot hold is held for review", async (t) => { + const root = await fixture(t); + for (const name of ["colon:name", "back\\slash", "tab\tname", "line\nbreak"]) await add(root, name, "id-" + name.length); + await writeFile(path.join(root, "bare\u0001.mp4"), "synthetic video bytes"); + await writeFile(path.join(root, "bare\u0001.vtt"), VTT); + const result = await scan(root); + assert.equal(result.candidates.length, 5); + for (const row of result.candidates) { + assert.equal(row.status, "issue", JSON.stringify(row.media)); + assert.match(row.issues[0], /^Media: the file name has a control character/); + assert.equal(row.fingerprint, undefined); + assert.equal(row.preparationFingerprint, undefined); + assert.equal(row.transcriptionFingerprint, undefined); + } +}); diff --git a/common/lib/localMediaScan.ts b/common/lib/localMediaScan.ts @@ -4,6 +4,7 @@ import type { Stats } from "node:fs"; import path from "node:path"; import { lstat, open, readdir, realpath } from "node:fs/promises"; import { extractVideoId } from "./videoId"; +import { isExternalMediaRelativePath } from "./localMedia"; import { parseVtt } from "./vtt"; // Read-only discovery, not an executable import plan. The caller supplies the @@ -114,8 +115,14 @@ export async function scanLocalMedia(options: { let metadataMissing = false; let transcriptText = ""; let metadataUsable = false; - try { mediaStat = await lstat(await regularFile(root, media)); } - catch (error) { row.issues.push(`Media: ${reason(error)}`); } + // A name the library reference cannot hold (a control character, \ or :) + // is held here: offered as new, its import could only fail. + if (!isExternalMediaRelativePath(media)) { + row.issues.push("Media: the file name has a control character, \\ or :, which a library reference cannot hold; rename the file"); + } else { + try { mediaStat = await lstat(await regularFile(root, media)); } + catch (error) { row.issues.push(`Media: ${reason(error)}`); } + } try { metadataText = await readLocalMediaText(root, row.metadata); const meta = JSON.parse(metadataText.replace(/^\uFEFF/, "")); diff --git a/common/lib/vtt.test.ts b/common/lib/vtt.test.ts @@ -121,6 +121,26 @@ test("timing lines do not partially match malformed or out-of-range stamps", () assert.deepEqual(parseVtt(`WEBVTT\n\n${stamp} --> 00:02.000\nInvalid\n`), [], stamp); } }); +test("a short-form stamp whose hours do not fit a number is not a cue line", () => { + const hours = "9".repeat(400); + assert.deepEqual(parseVtt(`WEBVTT\n\n${hours}:00:01.000 --> ${hours}:00:02.000\nToo long\n`), []); + assert.deepEqual(parseVtt(`WEBVTT\n\n00:01.000 --> ${hours}:00:02.000\nToo long\n\n00:03.000 --> 00:04.000\nKept\n`), + [{ start: 3, end: 4, text: "Kept" }]); +}); +// A hostile line (a long run of digits, spaces, tags or stamps) is read in time +// proportional to its length: every timing pattern is anchored or bounded. +test("a long hostile timing line is read in linear time", () => { + const lines = [ + "1".repeat(200_000) + ":00:01.000 --> 00:02.000", + "00:01.000" + " ".repeat(200_000) + "x", + "00:01.000 --> 00:02.000" + " ".repeat(200_000) + "\u0000", + "<".repeat(100_000) + "00:01.000".repeat(20_000), + "00:00:01.000 ".repeat(20_000), + ]; + const started = Date.now(); + for (const line of lines) parseVtt(`WEBVTT\n\n${line}\nText\n`); + assert.ok(Date.now() - started < 2000, `took ${Date.now() - started} ms`); +}); test("point cues preserve original text and timestamps", () => { assert.deepEqual(parseVtt("WEBVTT\n\n00:01.000 --> 00:01.000\nPoint\n"), [{ start: 1, end: 1, text: "Point" }]); diff --git a/common/lib/vtt.ts b/common/lib/vtt.ts @@ -110,6 +110,9 @@ export function parseVtt(src: string): Cue[] { const start = m ? parseTimestamp(m[1]) : parseShortTimestamp(short![1]); const end = m ? parseTimestamp(m[2]) : parseShortTimestamp(short![2]); i++; + // A short-form stamp's hours are unbounded digits: one too long to be a + // number is not a cue line, so no Infinity reaches cue JSON or the index. + if (!m && !(Number.isFinite(start) && Number.isFinite(end))) continue; const body: string[] = []; while (i < lines.length && lines[i].trim() !== "") { body.push(lines[i]);