Skip to content

fix(encode): publish the output only once the render succeeds - #279

Merged
LeadcodeDev merged 0 commit into
fix/transition-easingfrom
fix/encode-atomic-output
Sep 22, 2026
Merged

LeadcodeDev merged 0 commit into
fix/transition-easingfrom
fix/encode-atomic-output

Conversation

@LeadcodeDev

Copy link
Copy Markdown
Owner

Severity Medium, category correctness. Location: crates/rustmotion/src/encode/video/ffmpeg.rs:620

Impact

When render_frame_task fails mid-encode (line 613 sets pipe_error and breaks), the code drops stdin and then waits for ffmpeg. ffmpeg sees a clean EOF on pipe:0, finalizes the frames it already received, writes the moov atom and exits 0. rustmotion then returns Err, but output_path now holds a structurally valid MP4 containing only the first N frames. Because ffmpeg_args emits -y (line 194), this also silently destroys a previously-good render at the same path. A user scripting rustmotion render who checks only file existence (or whose CI publishes the artifact) ships a truncated video. No code path anywhere in src/cli or src/encode removes the output on failure — only test code calls remove_file on outputs.

Fix

On the pipe_error path, call child.kill() and child.wait() before returning, and let _ = std::fs::remove_file(output_path); on both the pipe_error and !status.success() branches. Better still, have ffmpeg write to a sibling scratch path and fs::rename onto output_path only after a clean exit — the same promote-on-success discipline video_audio.rs::partial_wav_path already applies to cached WAVs.

Evidence the audit read

drop(stdin);
...
    let status = child.wait().map_err(|e| RustmotionError::FfmpegWait {
        reason: e.to_string(),
    })?;
...
    if let Some(e) = pipe_error {
        tee_stderr();

Stacked on fix/transition-easing, which carries the previous finding of this workstream. GitHub shows only this finding's diff; merge in order.

Part of the September 2026 audit remediation chantier. Refs #220 (RM-17).

@LeadcodeDev LeadcodeDev added the bug Something isn't working label Sep 22, 2026
@LeadcodeDev LeadcodeDev self-assigned this Sep 22, 2026
@LeadcodeDev
LeadcodeDev added this pull request to stack #280 September 22, 2026 06:40
@LeadcodeDev
LeadcodeDev force-pushed the fix/encode-atomic-output branch 2 times, most recently from cec3505 to ca0729d Compare September 22, 2026 08:43
@LeadcodeDev
LeadcodeDev merged commit ca0729d into chantier/audit-2026-09 Sep 22, 2026
3 checks passed
@LeadcodeDev
LeadcodeDev deleted the fix/encode-atomic-output branch September 22, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant