Skip to content

fix(engine): extraction-time video downloads get the not-media and format checks - #7838

Merged
jrusso1020 merged 5 commits into
mainfrom
sec-low8c-1115
Nov 15, 2026
Merged

jrusso1020 merged 5 commits into
mainfrom
sec-low8c-1115

Conversation

@michaelwang11394

Copy link
Copy Markdown
Contributor

What

A video downloaded at extraction time is now checked before ffprobe or ffmpeg reads it. Two checks run:

  • the existing not-media check, which runs on every render;
  • on a render service only (PRODUCER_RESTRICT_PAGE_NETWORK on), a probe with the same -format_whitelist that https inputs already get.

Why

The extractor's download path handed the downloaded file to ffmpeg with neither check. The other paths into ffmpeg already had them. A file served as a video that was really an HLS playlist or a DASH manifest could make ffmpeg open the files that list names.

Related work

Refs #7807 (the format whitelist for https inputs) and #7810 (the byte-level playlist check). #7827 touches only urlDownloader.ts, which this PR doesn't edit.

How

  • services/videoFrameExtractor.ts: after downloadToTemp, assertDownloadedVideoIsMedia runs assertMediaPayload. A refused file is classified as invalid_media, which isn't retried, the same as the later probe already gave. On a render service it also runs one ffprobe with the whitelist, and passes the render's cancel signal through.
  • utils/urlInput.ts: the whitelist args move into selfContainedFormatArgs(), so both paths share one list. urlInputArgs output is unchanged.

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

  • The new videoFrameExtractor.downloadPayload.test.ts has three tests that fail on main and pass here:

    • a downloaded DASH manifest is refused before any probe;
    • on a render service, a downloaded HLS playlist is refused (on main it extracts frames);
    • the cancel signal reaches the probe.
  • Real mp4, mov and webm downloads give the same frames with the setting on and off.

  • Manual: ffprobe 8.0.1 with the whitelist opens mp4, mov, m4v, 3gp, fragmented mp4, HEVC, ProRes, mkv, webm, ts, avi, flv, wmv and mpg. It refuses raw h264, ivf, y4m, apng, mjpeg and raw mpeg4 streams, which matches the https path. The probe takes about 15 ms and runs once per video element.

  • Engine typecheck, the comment ratchet, fallow and verify:packed-manifests pass.

  • 14 tests in 5 other extractor and ffprobe files fail locally on both main and this branch, with identical lists. They come from the local ffmpeg 8.0.1 build.

  • Not run: a real DASH read, because the local ffmpeg has no DASH demuxer. On local renders only the not-media check runs.

A video src that is still remote at frame extraction is downloaded again and
then probed. That copy now gets the checks other media downloads get before
anything reads it as media:

- the not-media sniff, so an HTML, XML or JSON body (including a DASH
  manifest) is refused with the existing NotMediaPayloadError, classified as
  invalid_media;
- on a render service (PRODUCER_RESTRICT_PAGE_NETWORK), the same
  -format_whitelist an https input gets, so a playlist, manifest or concat
  list fails to open whatever its bytes say, and no file it names is read.

Real mp4, mov and webm downloads extract the same frames as before.
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 97 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)

  • seqab-none-px-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo false, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true
  • seqnudge-none-px-r0-nested-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

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

REQUEST_CHANGES — Important: preserve valid MP4 box headers in the new check. At packages/engine/src/services/videoFrameExtractor.ts:332, the newly applied assertMediaPayload rejects a valid fragmented MP4 whose ftyp box is 60 bytes. The shared sniff skips leading NUL bytes and interprets the box-size byte (0x3c) as a text prefix.

I generated a one-second H.264 fragmented MP4 with relative fragment addressing, expanded its compatible-brand list to a 60-byte ftyp, and passed it through the extraction download-return fixture. The existing downloader's real cache validation and ffprobe with the format whitelist both accept it. At this head, extraction returns invalid_media / “text documents” with PRODUCER_RESTRICT_PAGE_NETWORK both false and true. Removing only the new assertion call restores all 30 frames in both cases.

Please fix the shared sniff to distinguish valid binary BMFF box headers from text, retaining the manifest refusal, and add this fixture as a regression test. Removing validation is not the fix.

Validation: frozen install and full build passed. Gated Vitest: 16 committed cases plus a normal fragmented-MP4/MKV control passed; the two temporary odd-brand cases failed. With admission validation removed, those two cases pass and the three new manifest/signal guard tests fail. Normal MP4/MOV/WebM extraction matches with the restriction on/off. Source inspection confirms cached download returns meet the new check, the format list is shared with HTTPS inputs, and the probe receives the cancellation signal. No live service render was run.

Need: yes · Size: ok · Reuse: existing media sniff, runFfprobe and shared format list · Simpler: already minimal · Structure: fine (checked downloader and extraction boundary; no split)
Risk: medium — valid downloaded media can now fail before extraction.

— Rames

… as text

An ISO BMFF file opens with a 4-byte box size and a box type. A size of 60
is the byte `<`, so after the leading NULs were skipped a valid mp4 with a
60-byte ftyp was refused as a text document. The sniff now recognises an
mp4/mov box header (size 0, 1 or at least 8, then ftyp, styp, moov, moof,
mdat, free, skip, wide, sidx or pdin) before it skips NULs. HTML, XML,
JSON and playlist refusals are unchanged.
@michaelwang11394

Copy link
Copy Markdown
Contributor Author

Fixed in d8f7646 by changing the shared sniff, not by removing the check.

  • notMediaPayload.ts recognizes an ISO BMFF box header before it skips leading NUL bytes. That means a big-endian size of 0, 1, or 8 or more, followed by one of ftyp, styp, moov, moof, mdat, free, skip, wide, sidx or pdin. Such a file is treated as binary media. The HTML, XML, JSON and playlist refusals are unchanged.

  • Regression tests:

    • your case, a fragmented H.264 MP4 with a 60-byte ftyp generated with ffmpeg in the test;
    • box-size bytes that read as <, #, {, [ or whitespace;
    • box sizes 0 and 1;
    • an XML manifest behind NULs, still refused.

    The fixture test and three of the box-size cases fail on d10ff2e and pass now.

  • WebM/EBML, RIFF, Ogg, FLV and MPEG-TS needed no change, because none of them starts with a NUL or a text byte.

  • 11 engine test files pass, including all four urlDownloader files and notMediaPayload. The producer's sniff tests, the engine typecheck, the comment ratchet and verify:packed-manifests also pass.

The sniff is shared, so this also fixes the same false refusal for the other callers on main, such as downloader cache validation and local preflight.

One thing unchanged: an XML MPD behind an ID3 tag was never caught by the sniff. On a render service, the format whitelist still blocks it.

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

REQUEST_CHANGES — Important: bound the new BMFF exception to a plausible box. packages/engine/src/utils/notMediaPayload.ts:144 accepts a known box-type spelling and almost any size without checking that the declared box fits the file. I verified that non-media input previously rejected by this shared guard now reaches decoding. Restoring the previous sniff rejects the same input before decoding. This is introduced by the new shared-sniff exception, not the original extraction guard.

Please validate the header against the actual file length, including the extended-size header when size is 1, before exempting it from document detection. Add a non-media negative control alongside the positive BMFF cases. Keep the container whitelist: it still protects restricted downloaded-video extraction, but other shared-sniff callers do not all apply that additional check.

The original compatibility blocker is fixed: both of my previous 60-byte-ftyp cases now extract 30 frames, and normal fragmented MP4/MKV controls pass. The committed download-payload, media-sniff and URL-input suites pass 88 tests. Restoring the previous sniff makes the new committed fragmented-MP4 case and both original reviewer cases fail, while the new non-media negative control passes. Engine build passed; no deployed render was run.

Need: yes · Size: ok · Reuse: shared media sniff and format whitelist · Simpler: bounded header validation · Structure: fine (checked compiler, mixer, asset preflight and snapshot sniff callers; no split)
Risk: medium — the new shared exception admits a document previously refused.

Verdict: REQUEST_CHANGES
Reasoning: The valid-media regression is resolved, but the replacement exception introduces a reproducible document false negative. Preserve the compatibility fix with bounded header validation.

— Rames

…t fits the file

The sniff only skips its document check for an mp4/mov opening when the
first box is ftyp or styp, its declared size (including a 64-bit size) fits
the file length, and the next box header, when the sniff window holds it, is
a known media box that also fits. A document that only spells a box header
falls through to the document and playlist checks as before.
@michaelwang11394

Copy link
Copy Markdown
Contributor Author

Fixed in 3c0490c. The BMFF exception now requires a plausible box structure before it skips document detection:

  • The first box must be ftyp or styp, with a declared size that fits the actual file length (taken from fstat on the open file).
  • A size of 1 means the 64-bit size header must be at least 16 and fit the file.
  • When the next box header lies inside the read window, it must also be a known box type that fits the file.
  • Anything else falls through to the existing document and playlist checks, unchanged.

The new negative controls fail on d8f7646 and pass now:

  • a text document whose first 8 bytes spell a fake ftyp box with an oversized declared size;
  • a bad 64-bit size on the second box. A 64-bit size on the first box can't change the result, because the first box never starts with a text byte.

The 60-byte ftyp fragmented-MP4 regression and both of your earlier cases still pass. The notMediaPayload, download-payload, urlInput and urlDownloader tests pass, along with the typecheck, the comment ratchet and verify:packed-manifests. The container whitelist is unchanged.

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

The previous unbounded-header negative control is now refused, and both original 60-byte-ftyp fragmented-MP4 cases still extract successfully. The new file-length checks address that earlier finding.

Important — preserve valid BMFF padding and extension boxes (packages/engine/src/utils/notMediaPayload.ts:165, :153). The new first-box restriction rejects a valid fragmented MP4 with a leading 60-byte free box. The second-box type restriction also rejects a valid fragmented MP4 with a 60-byte ftyp followed by a uuid box. ffprobe accepts both, but extraction now returns invalid_media/“text documents” before decoding. The new restrictions reject these valid containers; this is separate from the previous fake-header failure.

Keep the bounded size checks, but recognize legal leading padding and extension boxes rather than requiring only ftyp/styp first and the current short type list second. Add both real-container extraction controls. A temporary change allowing the relevant padding/extension types makes both extract 30 frames and keeps the previous negative control rejected; it was restored, not pushed.

Validation: frozen install/full build; committed payload/sniff/URL-input suites plus original and added reviewer cases: 100 passed, 2 failed (the two valid-container cases above). The temporary fix passed 85 targeted tests. Additional size-0, extended-size, oversized-largesize and window-edge checks ran. A synthetic two-header/text case still passes the sniff but ffprobe rejects it; that alone is not evidence of an unsafe decoding path. No deployed render test.

Need: yes · Size: ok · Reuse: shared sniff and format whitelist · Simpler: preserve structural bounds without excluding legal container boxes · Structure: fine (checked shared classifier and extraction consumer; no split)
Risk: medium — valid customer media can be refused by a shared guard.

Verdict: REQUEST_CHANGES
Reasoning: The earlier false negative is fixed, but the narrowed box types introduce reproducible valid-media regressions. Preserve those containers while retaining the new bounds.

— Rames

… or extension boxes

An mp4 or QuickTime file may open with free, skip, wide, uuid, pdin, moov,
mdat or moof as well as ftyp or styp, and may carry any box type after it.
The sniff now accepts any of those first boxes, then walks every box header
the sniff window holds: each needs a printable four-character type and a
size that fits the file. A document that only spells a box header still
falls through to the document and playlist checks.
@michaelwang11394

Copy link
Copy Markdown
Contributor Author

Fixed in 6b8d668. The size bounds are unchanged; only the type restrictions are widened.

  • The first box can be ftyp, styp, or one of the legal leading padding or extension boxes: free, skip, wide, uuid, pdin, moov, mdat or moof.

  • Every box header in the read window is checked, not only the second one. Each needs a printable four-byte type (a © first byte is allowed for QuickTime), and a size that fits the file under the same rules as before:

    • a 64-bit size of at least 16;
    • size 0 only for a last box.

    Anything else falls through to document detection.

  • Both of your containers are now real extraction tests, built with ffmpeg in the test: a fragmented MP4 with a leading 60-byte free box, and a 60-byte ftyp followed by a uuid box. Both fail at 3c0490c and pass now. The earlier fake-header negative controls are still refused. The sniff, payload, urlInput and urlDownloader tests, the typecheck, the ratchet and verify:packed-manifests all pass.

@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 6b8d668bae21573f5bbfb8180274b65206ba3377, including the delta since 3c0490c2f04588a616ee867fa93c691af2629231.

The prior compatibility blockers are resolved: the real fragmented MP4 with a leading free box and the ftyp plus uuid file both extract successfully. The original fragmented-MP4 cases still work with restriction enabled and disabled, and the earlier non-media negative control remains refused. The new scan retains file-length and extended-size bounds while accepting the padding/extension types.

Validation: frozen install and full workspace build passed. Gated payload/sniff tests plus the original reviewer extraction controls: 98 passed. One additional test covering container-size and sniff-window boundaries also passes. Restoring the previous sniff makes the two repaired container cases fail in both committed and reviewer tests (4 failed, 17 passed); restored afterward. No deployed-service render or Windows run was performed.

Need: yes · Size: ok · Reuse: existing shared media sniff and format list · Simpler: bounded header validation · Structure: fine (checked shared classifier and extraction consumer; no split)
Risk: medium — shared media admission affects downloaded-video extraction.

Verdict: APPROVE
Reasoning: The reported valid-container regressions are fixed while the prior document refusal and structural size bounds remain exercised.

— Rames

@jrusso1020
jrusso1020 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit f0fb7aa Nov 15, 2026
91 checks passed
@jrusso1020
jrusso1020 deleted the sec-low8c-1115 branch November 15, 2026 19:31
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.

2 participants