Repository navigation
fix(studio): a long audio file from outside the project is never decoded for its waveform - #7961
Conversation
Edit accuracy: accurate 267 (base branch 267), smooth 98 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (2)
|
…ded for its waveform
4328b4c to
562797a
Compare
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Reviewed by Eddy's Claude agent at commit 562797a.
Verdict: approved as a partial guard; the remainder is stated below.
Summary. Studio drew waveform bars for an audio clip whose file lives outside the project by downloading the whole file and decoding it in the browser tab, so a long recording could use over a gigabyte of memory. The PR passes an empty audio URL to the waveform component unless the server has a waveform route for the file or the clip's source length is known and at most 15 minutes, so long or unprobed outside files are no longer fetched or decoded for bars. This narrows the accidental case correctly, but it is not a defence against a hostile project: the length it trusts can be declared in the project's own HTML, and there is no byte-size cap on the download. No SecOps finding is attached, the change adds no new weakness, and required CI checks were still pending when I finished.
A small hardening, and it does what it says for the ordinary case: an audio clip whose file lives outside the project gets waveform bars only when its length is known and at most 15 minutes, so a long or unprobed outside file is no longer downloaded and decoded in the tab for bars. In-project files keep their server waveform. All required checks pass.
It is a partial guard, and should not be read as protection against a hostile project. The length it trusts can be declared by the project itself (a data-source-duration attribute is read first), so a project can state a short length for a very long file; and length is the only bound, so a short but very large file is still downloaded and decoded in full. A byte cap on the download in the waveform decoder is the robust guard. Other whole-file decode paths in Studio have no bound at all; the reviewer lists them below.
Blockers
None.
Non-blockers
packages/studio/src/hooks/useRenderClipContent.ts:88: The 15-minute bound trusts a length the project or the file declares, so a hostile project can still force a whole-file download and decode.fitsBeatAnalysis(el)readsel.sourceDuration. That value comes first from the project's own HTML attribute (data-source-duration, timelineElementHelpers.ts:253-255), otherwise from the media element's reported duration, otherwise from the header probe (mediaProbe.ts:63). A project containing<audio src="<an outside URL>" data-source-duration="10">passes the gate, and AudioWaveform.tsx:146-152 then reads the whole response into memory and decodes it. A file whose header understates its length does the same. The honest-but-stale case (src swapped, attribute left behind) hits this too. I rate it non-blocking because the PR is stated as a memory fix for honest long files, it makes nothing worse than main, and no SecOps finding defines this as the attack path; but the PR body's claim that the page 'never downloads or decodes' a long outside file only holds when the declared length is true. To resolve: Put the guard in decodeWaveformPeaks itself: reject when Content-Length exceeds a byte cap and abort a streamed read past that cap, before arrayBuffer()/decodeAudioData. Optionally prefer the probed duration over the authored attribute for this decision.packages/studio/src/hooks/useRenderClipContent.ts:88: Duration is the only bound, so a short but very large outside file is still fully downloaded and decoded. renderAudioClip also builds the sound strip for video clips with sound (useRenderClipContent.ts:154-156, 254). An outside 12-minute multi-gigabyte video passessourceDuration <= 900, and AudioWaveform.tsx:148 buffers the entire file. A 15-minute 48 kHz stereo file decodes to roughly 345 MB of float samples (the PR's own capture shows 169 MB for 16 minutes), so 15 minutes is a mitigation, not a safe ceiling. To resolve: Same byte cap in the loader; consider decoding in an OfflineAudioContext at a low mono sample rate as useFxLevelling.ts:68 does.packages/studio/src/hooks/useRenderClipContent.ts:90: A skipped waveform looks identical to silence, and the guard lives at one call site of an exported component. With an empty audioUrl the lease is idle, and AudioWaveform only shows a notice on status 'error' (AudioWaveform.tsx:303), so a long or unprobed outside clip is blank with no explanation; a short outside file whose probe fails (for example no CORS on the range request) now also gets no bars. AudioWaveform is exported from packages/studio/src/index.ts:113, so any other caller passing an outside URL still decodes without a bound. To resolve: Move the limit into AudioWaveform/decodeWaveformPeaks with an explicit 'too long' state instead of the empty-string sentinel.
Fix criteria from the finding
- none: A long outside-project audio file (true length over 15 minutes, honestly reported) is not downloaded or decoded for waveform bars: met (packages/studio/src/hooks/useRenderClipContent.ts:88-90:
serverPeaksOrShortFile = waveformUrl !== undefined || fitsBeatAnalysis(el)andaudioUrl: serverPeaksOrShortFile ? audioUrl : ""; AudioWaveform.tsx:202,221 makes cacheKey empty and passes a null request to useThumbnailLease, so loadWaveform never runs.) - none: An outside file of unknown length is not decoded (fail closed): met (packages/studio/src/utils/timelineInspector.ts:90:
sourceDuration != null && sourceDuration <= MAX_BEAT_SOURCE_SECONDSreturns false for undefined.) - none: The bound cannot be bypassed by a project that lies about the file length: not met (packages/studio/src/player/lib/timelineElementHelpers.ts:253-257: sourceDuration is read from the project's
data-source-durationattribute first, then the media element's own duration; mediaProbe.ts:63 uses the file's container metadata. All three are attacker-controlled for a hostile project or file.) - none: A size cap on the download (Content-Length check or streaming abort) guards the decode: not met (packages/studio/src/player/components/AudioWaveform.tsx:146-152:
response.arrayBuffer()thendecodeAudioData(buffer)with no size check; unchanged by this PR.) - none: In-project files keep their server waveform regardless of length: met (useRenderClipContent.ts:85-88: waveformUrl is defined for project-relative files, so the first half of the condition is true and audioUrl is unchanged.)
- none: Regression test covers known-short, known-long and unknown length: met (packages/studio/src/hooks/useRenderClipContent.test.ts:193-212: 180 s keeps the URL; 62 min and undefined get an empty URL. It goes through renderClipContent, not the helper directly. No case at exactly 900 s here (timelineInspector.test.ts:226 covers the boundary on the helper) and none for an outside video's sound strip.)
Open outside this PR
- No download size cap in decodeWaveformPeaks (packages/studio/src/player/components/AudioWaveform.tsx:146-152): untouched code, the robust guard is still missing.
- Sibling whole-file fetch+decode paths with NO length or size bound: packages/studio/src/components/editor/useFxLevelling.ts:67-70 and packages/studio/src/components/editor/useFxCarveNodes.ts:99-102 (both resolve the clip src against the document base, so an outside URL is fetched and decoded whole; these run on a user action in the effects panel, not on open).
- Sibling with the SAME bound (same trust in declared length): beat analysis, packages/studio/src/hooks/useMusicBeatAnalysis.ts:130 gating packages/core/src/beats/beatDetection.ts:114-116.
- Preview runtime playback path packages/core/src/runtime/webAudioTransport.ts:420-437 fetches and decodes the whole audio src with no bound (inside the composition preview, not the Studio timeline).
- Server peak routes are project-only: clipPeaksUrl (packages/studio/src/player/components/clipPeakMap.ts:23-33) returns undefined for outside media, so no outside fetch there. PreviewPoster.tsx:111 fetches only the project's own poster URL.
- Opening a received project makes the user's browser request attacker-chosen URLs (IP disclosure, requests to local-network addresses): the media element in the preview and the header probe (packages/studio/src/player/lib/mediaProbe.ts:58-63) still fetch every outside src. Pre-existing; this PR does not change it, it only removes the extra waveform fetch for long or unprobed files.
- Whether a hostile project's own scripts in the preview iframe can exhaust tab memory regardless of this gate was not traced (iframe sandboxing not checked).
- Final state of required CI checks (Test (studio), Typecheck, Build) to be confirmed by the owner before merge.
CI: all required checks pass at 562797a (9 pass, 3 skipped); nothing failing or pending.
How this was reviewed: a code-review pass and a security-review pass against the Mythos finding, by a reviewer agent in an isolated checkout of this commit; I then read the core of the fix and the cited lines myself. Nothing was built or run.
What
A timeline audio clip whose file lives outside the project (an absolute URL) gets waveform bars only when its file is no longer than 15 minutes and its length is known. A longer or unprobed one shows the plain clip pill, and the page never downloads or decodes it for bars.
Why
A file inside the project gets its peaks from the server's
/waveform/route. A file outside it has no such route, soAudioWaveformfetched the whole file and decoded it on anAudioContext, at full length, to draw a strip a few hundred pixels wide. A one-hour remote recording costs the page about the same memory as the beat-analysis decode #7944 capped: over a gigabyte of decoded samples on open.Related work
Refs #7944, which owns the 15-minute rule (
fitsBeatAnalysisintimelineInspector.ts); this reuses it so both whole-file decodes in the page share one limit.How
renderAudioClip(useRenderClipContent.ts, the one place a clip's waveform is built, for audio clips and videos with sound) passes an emptyaudioUrlwhen there is nowaveformUrland the file does not fit the rule.AudioWaveformalready loads nothing for an empty source. The clip picks bars up once the player fills in a short file's length.Before
Studio from main (with #7944), a 10-second clip of a 16-minute file served from another origin. The page decodes the whole file to draw the bars. The yellow panel comes from the capture script, not from Studio: it lists every
decodeAudioDatacall the page made.After
Same project, same capture, on this branch: the clip shows no bars and nothing is decoded in 45 s. (The composition thumbnail at the top left is only timing: the before shot was taken at 7 s, before it loaded.)
Test plan
useRenderClipContent.test.ts, a clip of a remote file: 3 minutes keeps itsaudioUrl; 62 minutes and unknown length get none.useRenderClipContent.ts,expected [ 'https://cdn.example.com/talk.mp3', undefined ] to deeply equal [ '', undefined ]. With the fix, 39 of 39 pass in the changed files, 3 runs in a row.tsc --noEmit,oxlintandoxfmtclean.