Skip to content

fix(engine,producer,cli): media inputs refuse formats that open other files - #7931

Merged
vanceingalls merged 6 commits into
mainfrom
11-16-media_inputs_refuse_path_opening_formats
Nov 16, 2026
Merged

vanceingalls merged 6 commits into
mainfrom
11-16-media_inputs_refuse_path_opening_formats

Conversation

@vanceingalls

Copy link
Copy Markdown
Collaborator

What

Every ffprobe/ffmpeg read of composition media now passes -format_whitelist: the demuxers the installed ffmpeg reports, minus the ones that open other files or URLs on their own. The not-media check also looks past ID3v2 tags and covers playlist entries and <img> sources.

Why

  • Local inputs reached ffprobe/ffmpeg with no format limit, so a file whose bytes make ffmpeg pick a manifest-style demuxer (DASH, IMF) could have ffmpeg open other paths by itself. The src-level folder checks look only at the src path, not at what ffmpeg opens.
  • The not-media check treated an ID3-prefixed document as an MP3, accepted a playlist entry that is itself a manifest, and never looked at <img> sources.

Related work

Builds on #7928 and the checks from #7810 and #7838. That PR's position stands: local renders keep every demuxer they accept today, since a blanket self-contained list would refuse HLS and ffconcat playlists, APNG, CAF, AMR, AC3/DTS, raw H.264/HEVC, IVF and Y4M. So this is not a whitelist of self-contained formats. The list is "the installed ffmpeg's demuxers minus those that open other files or URLs on their own".

How

  • @hyperframes/parsers/ff-binaries: mediaInputFormatArgs(binary) lists <binary> -demuxers once per binary (synchronously, cached), drops input devices and the denylist, and returns -format_whitelist. It reads ffmpeg 4's two-column listing as well as the newer three-column one. If the binary cannot be asked, it falls back to the existing self-contained list and asks again next time, never to "no whitelist".
  • Denylist: dash, imf, mlv (opens sibling .M00 files), vobsub (opens the sibling .sub), dvdvideo, sdp, rtsp, rtp, sap (open network URLs), avisynth, vapoursynth (load scripts), and lavfi. I read the ffmpeg 8.1 libavformat source for every demuxer that calls io_open, avformat_open_input, ffio_open_whitelist or ffurl_open. mov external references are relative-only and reject .., image2 expands patterns from the input name only, and webm_dash_manifest opens nothing else, so those stay.
  • hls and concat stay allowed for every input. ffmpeg's hls.c, concatdec.c, dashdec.c and imfdec.c copy the parent's format whitelist into every nested open (ff_copy_whiteblacklists), so a list can never reach a denied demuxer, and the playlist folder walk still confines the paths a list names. A test runs real ffprobe on a concat list and an HLS playlist: with the whitelist minus the nested file's demuxer the nested open is refused, with the full list it opens.
  • urlInputArgs returns this list for local paths and http://, and for https outside restricted mode. Restricted-mode https is unchanged (protocol whitelist plus the self-contained list). It lists from ffprobe's own binary for tool: "ffprobe".
  • Reads that skipped urlInputArgs now use it: HDR window and first-tick extraction, alpha-plane probe, GIF and HEIC prep, the audio sidecar. The CLI snapshot, its held-video and seek probes, the lint HEVC probe and the core grade analyzer use mediaInputFormatArgs with their own binaries. Internal inputs (lavfi, rawvideo, files the producer wrote) are left alone, as is Studio's MEDIA_INPUT_ARGS.
  • notMediaPayload: ID3v2 tags are skipped before the first byte is classified, so an ID3-prefixed document is refused as video or audio while a real MP3 passes. A nested playlist entry that opens with <?xml, <MPD, <!DOCTYPE, <html or <SmoothStreamingMedia makes the list refused; encrypted segments and keys are not sniffed. isNotImagePayload refuses JSON, and markup whose root is not svg, for <img>; a prolog that outruns the 64 KiB window or a UTF-16 SVG is allowed.
  • The first-byte sniff stays defence in depth: the whitelist is what stops ffmpeg from picking a path-opening demuxer.

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

fails without the fix: urlInput.test.ts (local/http list, fallback, real-ffprobe nested concat and HLS), ffBinaries.test.ts "mediaInputFormatArgs" (ffmpeg 4 listing, retry after a failed listing), notMediaPayload.test.ts (ID3 plus markup, isNotImagePayload, a playlist naming a manifest), assetMediaType.test.ts "refuses a manifest as an image source", mediaInputFormats.test.ts (GIF, sidecar and HEIC reads), captureHdrResources.test.ts "pins FFmpeg seek/duration, raw frame count, and reservation lifetime".

  • I ran these against the base commit with only the test files copied in and they fail there.
  • Engine, producer, cli, core, lint and parsers pass tsc --noEmit; oxlint, oxfmt and the pre-commit gates pass. Scoped suites pass: engine urlInput, notMediaPayload, alphaPlaneProbe; parsers ffBinaries; producer assetMediaType, captureHdrResources, animatedGifPrep, heifImagePrep, audioSidecar; cli snapshot*; core mediaGradeAnalyzer; lint hevcPreviewLint.
  • Engine notMediaPayload "refuses a list behind an ID3 tag" fails locally on main as well (ffprobe 8.1.1 does not open the outside file there); it is unrelated to this change.
  • Known limit: the local ffmpeg has no dash demuxer, so no test opens a real MPD; the nested-open test proves the whitelist reaches nested opens, and the argument-level test proves the denylist.

🤖 Generated with 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 182acb2.

The new shared format policy is applied before the relevant media inputs, including the previously separate HDR, alpha, GIF, HEIF, sidecar, snapshot and grading paths. The existing restricted-HTTPS protocol policy remains intact. Failed demuxer discovery falls back to the narrower list without caching the failure. The final commit only makes the nested-probe test argv explicit; its behavior is unchanged.

I checked the nested-open assumption against FFmpeg's concat and HLS source and independently exercised the actual format-list helper with bounded, locally generated media. node /tmp/hf7931-benign.mjs through the test gate: 9 checks passed, covering old/new listing shapes, fallback, installed-format filtering, and both concat/HLS accepting an owned MPEG-TS segment with the complete list and refusing it when MPEG-TS is excluded. An initial smaller fixture was too short to pass the positive probe control; the successful run used the test's 32×32, 5-fps, one-second fixture. No network or outside-folder reads were exercised. The named fails without the fix: tests are present in the body; I did not rerun the complete package suites or their base mutations.

An independent static pass also found no introduced blocker. This is a demuxer restriction, not a universal filesystem/network sandbox: HLS/concat remain supported, HTTP playlist references retain their existing treatment, and a denylist derived from installed formats needs maintenance when FFmpeg adds formats. The first-byte/image checks remain defense in depth rather than a replacement for that policy.

Need: yes · Size: ok · Reuse: shared ff-binaries and urlInput helpers · Simpler: existing input guards extended in place · Structure: fine (checked shared binary resolution and media preflight; no split)
Risk: high — changes the accepted media formats across multiple FFmpeg input paths.

Verdict: APPROVE.
Reasoning: The guarded input paths preserve their existing options, the nested-format propagation has a positive and negative bounded control, and no introduced correctness blocker was found at this head.

— cutroom-review

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 90 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-pct-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.04, renderKey -, undo false, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.04, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.04, renderKey -, undo true, teleport true
  • seqplainkeys-none-px-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo false, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

vanceingalls and others added 5 commits November 16, 2026 00:09
Composition media read by ffprobe/ffmpeg now passes a format allowlist on every
input: the demuxers the installed ffmpeg reports, minus the ones that open other
files or URLs on their own (DASH, IMF and similar). hls and concat stay allowed,
since ffmpeg carries the list into every file they open. The HDR window,
alpha-plane, GIF, HEIC, audio-sidecar and snapshot reads that skipped it now use it.

The not-media check skips ID3v2 tags before it looks at the first byte, refuses a
playlist entry that is a document, and refuses JSON or non-SVG markup as an <img> src.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s and covers every media probe

The demuxer listing is read from the binary that enforces the flag, accepts ffmpeg 4's
two-column output, and a failed listing is asked again next time. The lint HEVC probe,
the grade analyzer and the snapshot probes use it too. A nested playlist entry is refused
only for a real document signature, so encrypted segments and keys are kept; an image whose
prolog outruns the sniff window, or that is UTF-16, is no longer refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…robe contract reads

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ktracking

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vanceingalls
vanceingalls force-pushed the 11-16-media_inputs_refuse_path_opening_formats branch from 182acb2 to f872016 Compare November 16, 2026 08:11
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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.

Approve. This carries my approval at 182acb2 forward to 5c2b1d7. Since then: the ReDoS fix in notMediaPayload.ts, a rebase onto main, and the parsers size budget.

Rebase: at the new merge-base, every file in the PR's own patch has the same git patch-id --stable as at 182acb2, except notMediaPayload.ts and its test.

Doctype/prolog scanner (f872016)

  • afterProlog replaces the MARKUP_PROLOG regex:
    • <?…?> and <!--…--> are skipped with indexOf.
    • afterDoctype walks from offset 9 and jumps each [ to its next ], the same as the old lazy \[[\s\S]*?\].
  • Every step moves forward, and the input is capped at IMAGE_SNIFF_BYTES (64 KiB), so the scan is linear.
  • isNotImagePayload keeps its semantics: still SVG after prologs, and an unterminated prolog in a truncated window still gets the benefit of the doubt.

Fails without the fix

  • I timed adversarial inputs in node against the scanner as shipped and the old regex.
  • Unclosed doctype <!DOCTYPE svg + "[]"×32000: the old regex didn't return within a 120s timeout. The new scanner takes 1.4 ms.
  • The other cases with the new scanner: the PR's 30k ][ subset 3.8 ms, 9,300 stacked <!----> 3.0 ms, an unterminated 65 KB doctype 0.3 ms.
  • vitest run src/utils/notMediaPayload.test.ts at this head: 94/94 pass, including the new long-subset row.

Budget (5c2b1d7): the only change is scripts/package-size-budgets.json parsers unpacked 900000 → 915000, against the measured 910341. The growth is the media-format list this PR adds to ffBinaries.ts.

CI: still running at the time of this review (21 pass, 33 pending, 0 failing).

Need: yes (CodeQL js/redos on the new sniff) · Size: ok · Reuse: nothing to reuse (the old regex was the only prolog parser) · Simpler: already minimal, three small helpers · Structure: fine (checked withoutLeadingBlanks/headText in the same file; no split)
Risk: low — a pure function rewrite with the same matches and test coverage; a budget bump with a measured reason.

Reviewed at 5c2b1d7.

— Rames

@vanceingalls
vanceingalls merged commit ead110a into main Nov 16, 2026
97 checks passed
@vanceingalls
vanceingalls deleted the 11-16-media_inputs_refuse_path_opening_formats branch November 16, 2026 08:35
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