Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(gif): one trailer per file, clean up a failed export, revert lockfile churn

Etienne Lescot202085404907
diff --git a/crates/Cargo.lock b/crates/Cargo.lock
index c265dc4ab..52c11e5e3 100644
--- a/crates/Cargo.lock
+++ b/crates/Cargo.lock
@@ -19,9 +19,9 @@ dependencies = [
[[package]]
name = "anyhow"
-version = "1.0.104"
+version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
+checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3"
[[package]]
name = "autocfg"
@@ -46,7 +46,7 @@ dependencies = [
"regex",
"rustc-hash",
"shlex 1.3.0",
- "syn 2.0.119",
+ "syn",
]
[[package]]
@@ -57,9 +57,9 @@ checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da"
[[package]]
name = "bytemuck"
-version = "1.25.2"
+version = "1.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797"
+checksum = "d6aedf8ae72766347502cf3cb4f41cf5e9cc37d28bee90f1fdaaae15f9cf9424"
[[package]]
name = "byteorder-lite"
@@ -69,9 +69,9 @@ checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
[[package]]
name = "cc"
-version = "1.4.0"
+version = "1.2.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5add81bb678e6cb321aff7fa0dc7689ad82b112dbc032cea19f91d6b8e3582b9"
+checksum = "e17dd265a7d0f31ef544e1b20e03add05d3b45b491b633b10d67145d2acc1a38"
dependencies = [
"find-msvc-tools",
"shlex 2.0.1",
@@ -140,14 +140,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a2785755761f3ddc1492979ce1e48d2c00d09311c39e4466429188f3dd6501"
dependencies = [
"quote",
- "syn 2.0.119",
+ "syn",
]
[[package]]
name = "either"
-version = "1.17.0"
+version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9e5e8f6c15a24b9a3ee5efec809ccd006d3b30e8b3bb63c39af737c7f87daa1d"
+checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e"
[[package]]
name = "fdeflate"
@@ -176,9 +176,9 @@ dependencies = [
[[package]]
name = "glob"
-version = "0.3.4"
+version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
+checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
[[package]]
name = "image"
@@ -212,9 +212,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
[[package]]
name = "libc"
-version = "0.2.189"
+version = "0.2.186"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
+checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
[[package]]
name = "libloading"
@@ -279,9 +279,9 @@ dependencies = [
[[package]]
name = "napi-build"
-version = "2.4.0"
+version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5282704fbe8d49b0cf8b08e3f33233416a528658f205c7e5ace63b582de0b11c"
+checksum = "c9c366d2c8c60b86fa632df75f745509b52f9128f91a6bad4c796e44abb505e1"
[[package]]
name = "napi-derive"
@@ -294,7 +294,7 @@ dependencies = [
"napi-derive-backend",
"proc-macro2",
"quote",
- "syn 2.0.119",
+ "syn",
]
[[package]]
@@ -309,7 +309,7 @@ dependencies = [
"quote",
"regex",
"semver",
- "syn 2.0.119",
+ "syn",
]
[[package]]
@@ -388,14 +388,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
dependencies = [
"proc-macro2",
- "syn 2.0.119",
+ "syn",
]
[[package]]
name = "proc-macro2"
-version = "1.0.107"
+version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
+checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
dependencies = [
"unicode-ident",
]
@@ -408,9 +408,9 @@ checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea"
[[package]]
name = "quote"
-version = "1.0.47"
+version = "1.0.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
+checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"
dependencies = [
"proc-macro2",
]
@@ -458,9 +458,9 @@ checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
[[package]]
name = "serde"
-version = "1.0.229"
+version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
+checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
dependencies = [
"serde_core",
"serde_derive",
@@ -468,29 +468,29 @@ dependencies = [
[[package]]
name = "serde_core"
-version = "1.0.229"
+version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
+checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
-version = "1.0.229"
+version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
+checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
- "syn 3.0.3",
+ "syn",
]
[[package]]
name = "serde_json"
-version = "1.0.151"
+version = "1.0.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14"
+checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"
dependencies = [
"itoa",
"memchr",
@@ -528,17 +528,6 @@ dependencies = [
"unicode-ident",
]
-[[package]]
-name = "syn"
-version = "3.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
-dependencies = [
- "proc-macro2",
- "quote",
- "unicode-ident",
-]
-
[[package]]
name = "unicode-ident"
version = "1.0.24"
@@ -582,7 +571,7 @@ checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.119",
+ "syn",
]
[[package]]
@@ -593,7 +582,7 @@ checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.119",
+ "syn",
]
[[package]]
diff --git a/crates/compositor/src/gif_export.rs b/crates/compositor/src/gif_export.rs
index 836eb3b9a..2fe600ede 100644
--- a/crates/compositor/src/gif_export.rs
+++ b/crates/compositor/src/gif_export.rs
@@ -146,6 +146,9 @@ impl Default for GifExportParams {
/// Drive a single-clip GIF export end-to-end. Mirrors the shape of
/// `pipeline::run_composited` so the bench can compare apples to
/// apples once the readback cost has been measured.
+/// A failed run leaves a truncated GIF under exactly the name the user thinks
+/// they exported. Remove it rather than leave it lying around — same contract
+/// as `discard_partial_output` on the MP4 path.
pub fn export_gif(
screen: &str,
webcam: &str,
@@ -153,6 +156,21 @@ pub fn export_gif(
out_path: &Path,
params: &GifExportParams,
progress: &mut dyn FnMut(u64),
+) -> Result<GifStats> {
+ let result = export_gif_inner(screen, webcam, cursor_json, out_path, params, progress);
+ if result.is_err() {
+ let _ = std::fs::remove_file(out_path);
+ }
+ result
+}
+
+fn export_gif_inner(
+ screen: &str,
+ webcam: &str,
+ cursor_json: Option<&str>,
+ out_path: &Path,
+ params: &GifExportParams,
+ progress: &mut dyn FnMut(u64),
) -> Result<GifStats> {
let width = params.width.unwrap_or(DEFAULT_GIF_WIDTH);
let height = params.height.unwrap_or(DEFAULT_GIF_HEIGHT);
@@ -332,6 +350,8 @@ struct GifWriter<W: Write> {
w: W,
width: u16,
height: u16,
+ /// Set by `finish`, so `Drop` does not append a second trailer.
+ finished: bool,
}
impl<W: Write> GifWriter<W> {
@@ -339,7 +359,12 @@ impl<W: Write> GifWriter<W> {
if width == 0 || height == 0 {
bail!("gif: dimensions must be > 0 (got {width}x{height})");
}
- Ok(GifWriter { w, width, height })
+ Ok(GifWriter {
+ w,
+ width,
+ height,
+ finished: false,
+ })
}
/// Write the GIF89a header + Logical Screen Descriptor. No global
@@ -434,6 +459,10 @@ impl<W: Write> GifWriter<W> {
/// path that wants an explicit "we're done, no more frames"
/// signal.
fn finish(&mut self) -> Result<()> {
+ if self.finished {
+ return Ok(());
+ }
+ self.finished = true;
self.w.write_all(&[0x3B])?;
self.w.flush()?;
Ok(())
@@ -442,12 +471,15 @@ impl<W: Write> GifWriter<W> {
impl<W: Write> Drop for GifWriter<W> {
fn drop(&mut self) {
- // Best-effort trailer; if the buffer failed before, this is
- // also the path that records the failure. We intentionally
- // don't propagate the result — `Drop` can't return errors.
- // A failed write is logged and the process continues; the
- // resulting file will be truncated/invalid, which the
+ // Best-effort trailer for the paths that bail out before calling
+ // `finish`. Skipped when `finish` already wrote one — two trailer
+ // bytes are tolerated by most decoders but rejected by strict ones.
+ // We intentionally don't propagate the result — `Drop` can't return
+ // errors. The resulting file will be truncated/invalid, which the
// caller will detect on the next read.
+ if self.finished {
+ return;
+ }
let _ = self.w.write_all(&[0x3B]);
let _ = self.w.flush();
}
@@ -920,6 +952,36 @@ mod tests {
/// The most basic round-trip: write a 2×2 frame and check the
/// file is well-formed GIF89a. No decode — we just walk the
/// output bytes and confirm the structural shape.
+ #[test]
+ fn gif_writer_writes_exactly_one_trailer() {
+ // `finish` writes 0x3B, and so does `Drop`. Without the guard the file
+ // ends `3B 3B`, which strict decoders reject.
+ let mut buf = Vec::new();
+ {
+ let mut gw = GifWriter::new(&mut buf, 2, 2).unwrap();
+ gw.write_header().unwrap();
+ gw.finish().unwrap();
+ }
+ assert_eq!(buf.last(), Some(&0x3B));
+ assert_ne!(
+ buf[buf.len() - 2],
+ 0x3B,
+ "trailer written twice: {:02X?}",
+ &buf[buf.len() - 2..]
+ );
+ }
+
+ #[test]
+ fn gif_writer_drop_still_terminates_without_finish() {
+ // The bail-out paths never call `finish`; `Drop` must still close the file.
+ let mut buf = Vec::new();
+ {
+ let mut gw = GifWriter::new(&mut buf, 2, 2).unwrap();
+ gw.write_header().unwrap();
+ }
+ assert_eq!(buf.last(), Some(&0x3B));
+ }
+
#[test]
fn gif_writer_writes_minimal_header() {
let mut buf = Vec::new();