Repository navigation
fix(engine,producer,cli): media inputs refuse formats that open other files - #7931
Conversation
jrusso1020
left a comment
There was a problem hiding this comment.
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
Edit accuracy: accurate 267 (base branch 267), smooth 90 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (2)
|
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>
182acb2 to
f872016
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jrusso1020
left a comment
There was a problem hiding this comment.
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)
afterPrologreplaces theMARKUP_PROLOGregex:<?…?>and<!--…-->are skipped withindexOf.afterDoctypewalks 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. isNotImagePayloadkeeps 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.tsat 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
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
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> -demuxersonce 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".dash,imf,mlv(opens sibling.M00files),vobsub(opens the sibling.sub),dvdvideo,sdp,rtsp,rtp,sap(open network URLs),avisynth,vapoursynth(load scripts), andlavfi. I read the ffmpeg 8.1libavformatsource for every demuxer that callsio_open,avformat_open_input,ffio_open_whitelistorffurl_open.movexternal references are relative-only and reject..,image2expands patterns from the input name only, andwebm_dash_manifestopens nothing else, so those stay.hlsandconcatstay allowed for every input. ffmpeg'shls.c,concatdec.c,dashdec.candimfdec.ccopy 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.urlInputArgsreturns this list for local paths andhttp://, 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 fortool: "ffprobe".urlInputArgsnow 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 usemediaInputFormatArgswith their own binaries. Internal inputs (lavfi, rawvideo, files the producer wrote) are left alone, as is Studio'sMEDIA_INPUT_ARGS.notMediaPayload: ID3v2 tags are skipped before the first byte is classified, so anID3-prefixed document is refused as video or audio while a real MP3 passes. A nested playlist entry that opens with<?xml,<MPD,<!DOCTYPE,<htmlor<SmoothStreamingMediamakes the list refused; encrypted segments and keys are not sniffed.isNotImagePayloadrefuses JSON, and markup whose root is notsvg, for<img>; a prolog that outruns the 64 KiB window or a UTF-16 SVG is allowed.Test plan
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".tsc --noEmit; oxlint, oxfmt and the pre-commit gates pass. Scoped suites pass: engineurlInput,notMediaPayload,alphaPlaneProbe; parsersffBinaries; producerassetMediaType,captureHdrResources,animatedGifPrep,heifImagePrep,audioSidecar; clisnapshot*; coremediaGradeAnalyzer; linthevcPreviewLint.notMediaPayload"refuses a list behind an ID3 tag" fails locally onmainas well (ffprobe 8.1.1 does not open the outside file there); it is unrelated to this change.dashdemuxer, 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