Repository navigation
fix(engine): extraction-time video downloads get the not-media and format checks - #7838
Conversation
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.
Edit accuracy: accurate 267 (base branch 267), smooth 97 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (2)
|
jrusso1020
left a comment
There was a problem hiding this comment.
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.
|
Fixed in d8f7646 by changing the shared sniff, not by removing the check.
The sniff is shared, so this also fixes the same false refusal for the other callers on 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
left a comment
There was a problem hiding this comment.
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.
|
Fixed in 3c0490c. The BMFF exception now requires a plausible box structure before it skips document detection:
The new negative controls fail on d8f7646 and pass now:
The 60-byte |
jrusso1020
left a comment
There was a problem hiding this comment.
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.
|
Fixed in 6b8d668. The size bounds are unchanged; only the type restrictions are widened.
|
jrusso1020
left a comment
There was a problem hiding this comment.
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
What
A video downloaded at extraction time is now checked before ffprobe or ffmpeg reads it. Two checks run:
PRODUCER_RESTRICT_PAGE_NETWORKon), a probe with the same-format_whitelistthat 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: afterdownloadToTemp,assertDownloadedVideoIsMediarunsassertMediaPayload. A refused file is classified asinvalid_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 intoselfContainedFormatArgs(), so both paths share one list.urlInputArgsoutput 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.tshas three tests that fail onmainand pass here:mainit extracts frames);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-manifestspass.14 tests in 5 other extractor and ffprobe files fail locally on both
mainand 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.