Skip to content

fix(engine,cli): the playlist folder check reads HLS as ffmpeg does; snapshot runs it too - #7810

Merged
michaelwang11394 merged 9 commits into
mainfrom
sec-playlist6-1115
Nov 15, 2026
Merged

michaelwang11394 merged 9 commits into
mainfrom
sec-playlist6-1115

Conversation

@michaelwang11394

Copy link
Copy Markdown
Contributor

What

  • The playlist folder check reads a playlist the way ffmpeg does. The check from fix(engine): refuse media playlists that name files outside their folder #7768 and fix(engine): media playlists are checked through every list they name #7778 now splits and cuts lines on raw bytes:
    • lines end at CR, LF or NUL;
    • each line is cut at 4095 bytes, ffmpeg's limit;
    • URI= values are split as ffmpeg splits them, quoted or unquoted, with backslash escapes removed;
    • leading ID3 tags are skipped, and more than 16 are refused.
      Nested lists are opened by their raw byte names. A nested list that exists but can't be read is refused instead of counted as safe.
  • hyperframes snapshot runs the same check before ffprobe or ffmpeg sees a project video. It checks each video once per command and warns once.

Why

The check read HLS more narrowly than ffmpeg's hls demuxer, so a local playlist could name a file outside its folder that ffprobe 8.0.1 would open. Each case below passed the old check, and ffprobe 8.0.1 opened the outside file:

  • a bare CR line end;
  • a NUL;
  • an unquoted or backslash-escaped EXT-X-MAP URI;
  • an unquoted EXT-X-MEDIA URI;
  • an ID3 prefix;
  • a line cut at 4095 bytes;
  • invalid UTF-8 bytes that moved the 4095-byte cut;
  • (on Linux) a nested list name that isn't valid UTF-8.

snapshot skipped the check entirely.

Related work

Refs #7768, #7778 (the check this extends).

How

  • engine/utils/notMediaPayload.ts: hlsEntries parses raw bytes. textStart skips ID3. readHead takes a start position. Each file's verdict is cached per call, and the ID3 header and 512-byte start are read in one open.
  • cli/commands/snapshot.ts: the engine check runs once per video per command.

Test plan

  • Unit tests added/updated

  • Manual testing performed

  • Documentation updated (if applicable)

  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

  • engine notMediaPayload.test.ts 58 pass. Every bypass above is a test that runs ffprobe 8.0.1, and each fails on main. The non-UTF-8 name case runs on Linux and skips on macOS.

  • These still pass: a master playlist with an audio track, a variant in a subfolder, EXT-X-MAP with byte ranges, ./ paths, CRLF, EXT-X-KEY, query strings, https segments, and a DATERANGE attribute containing URI=.

  • CLI snapshot tests 123 pass. Producer assetMediaType and engine urlDownloader/audioMixer pass.

  • Timing: 100k segments naming one file take 34 ms (main 4.3–5.2 s). 100k distinct files take 8.4–9.1 s (main 7.7–8.5 s).

  • Manual: hyperframes snapshot refuses an escaping playlist with a "not media" warning, and still shows a real frame for a playlist whose segments sit beside it.

  • A local playlist naming http(s) segments is already refused by ffmpeg ("not on whitelist 'file,crypto,data'"); verified.

  • Not covered: .. through a symlink inside the project. That predates this PR, and the OS resolves it.

…as ffmpeg does

The folder check now finds every name ffmpeg's hls demuxer would open:
- lines end at CR, LF or NUL, and a line is also read cut at ffmpeg's
  4095-byte limit;
- URI attributes are split like ff_parse_key_value: quoted or bare values,
  with backslash escapes removed;
- leading ID3v2 tags are skipped before the playlist signature, and a file
  behind more than 16 of them is refused.

Each refused shape is checked against ffprobe 8 in the test: ffprobe opens
the outside file, and playlistLeavesItsFolder now refuses the list.
…ent or an escaping playlist

`hyperframes snapshot` decodes held project videos with FFmpeg and FFprobe.
It now runs the engine's media check first: a file that is a document, or an
HLS or ffconcat list naming files outside its folder (under any extension),
is skipped with a "not media" warning and never reaches FFprobe or FFmpeg.
Real clips and HLS lists of segments beside them snapshot as before.
…le nested lists

- Playlist text is read as latin1, one character per byte, so a line is cut
  at 4095 bytes exactly where ffmpeg cuts it, even when it holds bytes that
  are not UTF-8. Nested names are opened by those same bytes.
- A nested name that exists but cannot be read is refused; a name that does
  not exist, or is too long to exist, is still kept.
- Each name is checked once, each file is opened once (ID3 header and head
  in one read), and each file's verdict is reused within a call: 100k
  segments naming one file drop from seconds to tens of milliseconds.
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 98 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

Unstable (2)

  • seqrepeat-none-center-r0-nested-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true
  • seqplainkeys-none-pct-r0-nested-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@michaelwang11394

Copy link
Copy Markdown
Contributor Author

CI fixes, on top of a merge of main:

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 7792cdb

The HLS parsing cases agree with the checked FFmpeg 8.0.1 source contracts and pass against the local 8.0.1-based ffprobe. Valid-playlist controls and the repeated/distinct large-list checks pass. Snapshot's newly added inspection introduces a separate availability regression. The head moved during review: the merge preserves this production code, adds a test-invocation correction and a size-budget change; dependencies were freshly installed and rebuilt before re-running the relevant checks.

Important — bound file inspection before the subprocess deadline (packages/cli/src/commands/snapshotHeldVideos.ts:95, packages/engine/src/utils/notMediaPayload.ts:104–110,318–320). A non-regular project video can leave the new awaited file inspection blocked before runCancellableProcess is called. Its 30-second subprocess timeout therefore never starts. The temporary regression probe confirms the call remains unresolved before reaching the mocked subprocess boundary; removing only the new inspection restores completion. The initial held-video hints are also requested before snapshot enters its capture cleanup scope.

Fix: make the shared inspection refuse or skip non-regular inputs without a blocking open, and keep inspection under a cancellation/deadline boundary. A nonblocking open followed by descriptor type validation avoids replacing this with a check/open race. Cover both the held-video hint and per-frame inspection callers; retain a regression that finishes without needing an external producer for the file.

Validation: frozen install/full bun run build passed. Engine payload/downloader suites: 150 committed tests plus 1 temporary large-list case passed. The 100,000-entry repeated/distinct fixtures took approximately 40 ms / 2.7 s on this host. At this head, the held-video suite has 24 committed tests passed, with 1 temporary availability probe failing (blocked-before-process instead of completion). Removing only the new inspection makes the availability probe pass; reverting the parser gives 11 parity failures, 1 pass. Temporary changes were restored. An earlier pre-merge snapshot unit sweep passed 200 committed tests; its broader browser sweep was stopped after four late-image cases failed; those browser failures were not attributed to this change. No live dev or cloud walkthrough performed.

Commands through the shared gate: engine bun run --cwd packages/engine test src/utils/notMediaPayload.test.ts src/utils/urlDownloader.test.ts --maxWorkers=1; snapshot bun run test src/commands/snapshotHeldVideos.test.ts --project unit --maxWorkers=1 from the CLI package.

Source checks: FFmpeg's line reader, attribute parser and ID3 header/length handling.

Need: yes · Size: focused parser and snapshot integration · Reuse: shared media inspection and existing cancellable process boundary · Simpler: keep the shared inspection bounded · Structure: fine (checked byte parser, nested-file walk and both snapshot inspection callers; no further split)
Risk: medium — untrusted media inspection can stall a local snapshot before its timeout and cleanup boundaries.

Verdict: REQUEST CHANGES
Reasoning: The parser fixes are supported by source and executable controls, but the new pre-probe inspection can hang snapshot indefinitely.

— Rames

The document sniff and the playlist walk open with O_RDONLY|O_NONBLOCK where
the platform has it, fstat the descriptor, and refuse anything that is not a
regular file before reading; a folder still fails as it did. A FIFO with no
writer, as a media source or named in a list, is refused at once.
…and its cleanup scope

The held-video hints are gathered inside the capture's cleanup scope, and
every media inspection gives up after the same 30 s limit as the FFprobe
call it guards, treating the file as not media.
@michaelwang11394

Copy link
Copy Markdown
Contributor Author

Fixed in d4bcdff and 29264de.

  • Engine: files open with O_RDONLY|O_NONBLOCK, and anything that isn't a regular file is refused by its descriptor type before any read. That includes nested lists. Symlinks are still followed, as today.
  • CLI: snapshot gathers the held-video hints inside the capture cleanup scope, and each inspection has the same 30 s deadline as ffprobe.

Four FIFO tests (skipped on Windows) finish without a writer and hang on the previous code. A real snapshot on a FIFO finished in 6 s.

🤖 Addressed by Claude Code

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 29264de

The previous availability finding is fixed. Both the initial media inspection and nested playlist reads now use a nonblocking open followed by descriptor-type validation before reading (packages/engine/src/utils/notMediaPayload.ts:103–119,335–338). Rejected handles close, and accepted handles retain their existing finally cleanup. Snapshot bounds both inspection callers and gathers its hints inside capture-server cleanup (packages/cli/src/commands/snapshotHeldVideos.ts:47–64,108, packages/cli/src/commands/snapshot.ts:1023–1026).

Validation through the shared gate: fresh frozen install/full bun run build passed. Payload/downloader suites: 152 committed tests passed, including the real FFprobe parser controls. Focused snapshot, held-video, HDR and frame-bank suites: 137 committed tests plus 2 temporary probes passed. The original FIFO availability probe now completes without a writer; removing only the nonblocking flag makes it fail again (blocked-before-process). The second temporary probe checks both 30-second inspection deadlines and that their timers are cleared. Temporary changes restored.

Commands: bun run --cwd packages/engine test src/utils/notMediaPayload.test.ts src/utils/urlDownloader.test.ts --maxWorkers=1; bun run --cwd packages/cli test src/commands/snapshotHeldVideos.test.ts src/commands/snapshot.test.ts src/commands/snapshotFrameBank.test.ts src/commands/snapshotHdrFrame.test.ts src/commands/reviewSnapshotDeadline.test.ts --project unit --maxWorkers=1. The last file was a temporary diagnostic.

Scope: re-reviewed the two-commit delta and complete inspection helpers/callers, retaining the prior raw-byte parser review. The deadline bounds caller waiting; it does not cancel an outstanding regular-file I/O operation. No browser render, Windows, dev or cloud walkthrough repeated.

Need: yes · Size: focused availability repair · Reuse: shared media reader and existing snapshot cleanup scope · Simpler: descriptor validation before reads, one deadline helper for both callers · Structure: fine (checked both shared read paths, both snapshot callers and server cleanup; no further split)
Risk: medium — shared untrusted-media inspection and snapshot file handling change.

Verdict: APPROVE
Reasoning: The blocking FIFO path is removed before reading, both callers have bounded waiting, and the original regression probe discriminates the fix.

— Rames

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 797a622 Nov 15, 2026
93 checks passed
@michaelwang11394
michaelwang11394 deleted the sec-playlist6-1115 branch November 15, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants