Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

web: WebCodecs busy check honours STALE_MS; checked row offsets in plane()

Brandon Thomas183884fd34a0
diff --git a/apps/filmcraft-web/src/webcodecs.rs b/apps/filmcraft-web/src/webcodecs.rs
index aae035d46..99b3df3bd 100644
--- a/apps/filmcraft-web/src/webcodecs.rs
+++ b/apps/filmcraft-web/src/webcodecs.rs
@@ -473,9 +473,10 @@ impl WcSource {
// already output but the cache dropped needs a restart).
let covers = !s.needs_key && s.start <= i && key <= s.next && (i >= s.next || want > s.out_max.get());
if !covers {
- // Don't interrupt a session that is still working towards its own frame.
- let busy =
- s.copying.get() > 0 || (!s.needs_key && s.target != i64::MIN && s.out_max.get() < s.target && now_ms() - s.last_output.get() < STALE_MS);
+ // Don't interrupt a session that is still working towards its own frame, unless it
+ // has gone quiet for STALE_MS (a copyTo that never settles must not wedge it).
+ let fresh = now_ms() - s.last_output.get() < STALE_MS;
+ let busy = fresh && (s.copying.get() > 0 || (!s.needs_key && s.target != i64::MIN && s.out_max.get() < s.target));
if busy {
return Drive::Waiting;
}
diff --git a/apps/filmcraft-web/src/webcodecs/pixels.rs b/apps/filmcraft-web/src/webcodecs/pixels.rs
index 7cd5eff54..dc99e7711 100644
--- a/apps/filmcraft-web/src/webcodecs/pixels.rs
+++ b/apps/filmcraft-web/src/webcodecs/pixels.rs
@@ -67,9 +67,10 @@ fn plane(raw: &js_sys::Uint8Array, layout: &JsValue, width: u32, height: u32) ->
raw.subarray(offset, end).copy_to(&mut out);
} else {
for (y, row) in out.chunks_exact_mut(width as usize).enumerate() {
- // Bounds/overflow checked for the last row above; earlier rows are smaller.
- let start = offset + y as u32 * stride;
- raw.subarray(start, start + width).copy_to(row);
+ // Checked for the last row above; earlier rows are smaller, but stay checked anyway.
+ let start = u32::try_from(y).ok().and_then(|y| y.checked_mul(stride)).and_then(|n| offset.checked_add(n)).ok_or("layout")?;
+ let row_end = start.checked_add(width).filter(|e| *e <= end).ok_or("layout")?;
+ raw.subarray(start, row_end).copy_to(row);
}
}
Ok(out)