From 11603ec0d159c2d117c2064eb85d284e4c4e80c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 10 Aug 2026 13:11:42 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(engine,ui):=20paste=20respec?= =?UTF-8?q?ts=20lane=20kinds;=20bounds=20and=20rebind=20capture=20hardened?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Four bugs a hunter sweep found, each with the door it comes in through: - `Project::paste` put the clipboard clip in the first lane of *every* kind, so an audio-only clip copied off A1 landed on V1 too: a wav as a video source, a decode that fails, and a save the next open refuses. It now asks the source what it is, the same question `place_stream_at` asks an import, and reaches A1 only when there is no picture. - The `resolution` line was applied unbounded while the keystroke capped at 8K, so a crafted `resolution 4294967295 4294967295` panicked `open_black` with a capacity overflow. One bound now (`engine::is_resolution`) with both doors asking it, and the load door refuses by line like every other malformed line. - `open_room` shifted starts unbounded, and the file format permits a clip ending at the very last frame: a paste wrapped it round to the front of the lane -- a debug panic, or in release an overlap no reload accepts. The edit door refuses the paste that would push anything past `u32::MAX`; the load bound stays where it is, since the wrap was the edit's to prevent. - A rebind captured whatever gpui reported, so shift+= wrote `play +` and the next load threw the *whole* keybindings file away, losing every other rebind. Capture now takes only a chord the file can spell and read back, and a line the parser cannot use costs that line alone -- the magic line is the only thing that still refuses the file. --- crates/app/src/keymap.rs | 195 +++++++++++++++++++++++------ crates/app/src/main.rs | 11 ++ crates/engine/src/edith.rs | 5 +- crates/engine/src/lib.rs | 14 +++ crates/engine/src/playback.rs | 3 +- crates/engine/src/project.rs | 117 +++++++++++++++-- crates/engine/tests/audio_files.rs | 45 +++++++ crates/engine/tests/saveload.rs | 12 ++ 8 files changed, 349 insertions(+), 53 deletions(-) diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 87200b9..ad84694 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -14,10 +14,12 @@ //! compares against that string and nothing translates in between. What a //! *person* reads is [`Keymap::display`]'s business, and only there. //! -//! The parser is strict and every refusal names its 1-based line, like the -//! project file: this file is generated by the keybindings editor, so a line it -//! did not generate is a corrupt file rather than a dialect. A missing file is -//! not corrupt -- it means nobody has changed a key yet, and the defaults stand. +//! The parser is strict and everything it cannot use names its 1-based line, +//! like the project file. Only the first line refuses the whole file: a binding +//! line the parser cannot use is *dropped*, named in the notice, and every other +//! line still stands -- one unusable line is not a reason to throw away the +//! rebinds around it. A missing file is not corrupt either -- it means nobody +//! has changed a key yet, and the defaults stand. //! //! Writing mirrors `engine::edith::save`: `.part`, fsync, rename, directory //! fsync, so an interrupted save cannot cost the bindings that were already @@ -323,6 +325,16 @@ impl Chord { } } + /// Whether the file can carry this stroke and read it back as itself. gpui + /// reports strokes this format cannot spell -- shift+= arrives as the key + /// `"+"`, which is the chord grammar's own separator -- and binding one + /// would write a line the next load has to drop. Asked before a capture is + /// taken, so a stroke that cannot be saved is refused while the user is + /// still looking at the row. + pub fn bindable(&self) -> bool { + Chord::parse(&self.text(), 0).is_ok_and(|round_trip| round_trip == *self) + } + /// Strict: exactly one optional `ctrl+` and then a key gpui could have /// reported. A spelling this cannot emit back unchanged is refused rather /// than normalised, because the round-trip is what makes the file editable @@ -504,7 +516,17 @@ impl Keymap { } }; match parse(&text) { - Ok(keymap) => (keymap, None), + Ok((keymap, dropped)) if dropped.is_empty() => (keymap, None), + // The lines it could use are in force; the ones it could not are + // named, and only those are lost. + Ok((keymap, dropped)) => ( + keymap, + Some(format!( + "KEYBINDINGS PART-READ — {}, {} — those strokes are unbound", + path.display(), + dropped.join("; ") + )), + ), Err(e) => ( Self::defaults(), Some(format!( @@ -590,7 +612,13 @@ fn emit(keymap: &Keymap) -> String { out } -fn parse(text: &str) -> Result { +/// The magic line is the whole of what makes this a keybindings file, so it is +/// the only thing refused outright. A *binding* line this parser cannot use is +/// dropped instead, and named in the returned warnings: one unusable line used +/// to cost every other rebind in the file, which is the user's data. What +/// survives is still exactly what emits back, so the by-hand round-trip holds +/// for every line that is kept. +fn parse(text: &str) -> Result<(Keymap, Vec), String> { // One trailing newline terminates the last line rather than starting an // empty one; a second is an empty line and is refused below. let body = text.strip_suffix('\n').unwrap_or(text); @@ -604,26 +632,38 @@ fn parse(text: &str) -> Result { } let mut bindings: Vec = Vec::new(); + let mut dropped: Vec = Vec::new(); for (i, line) in lines { let n = i + 1; let Some((name, chord)) = line.split_once(' ') else { - return Err(format!("line {n}: {line:?} is not ` `")); + dropped.push(format!("line {n}: {line:?} is not ` `")); + continue; + }; + let Some(action) = ActionId::from_name(name) else { + dropped.push(format!("line {n}: unknown action {name:?}")); + continue; + }; + let chord = match Chord::parse(chord, n) { + Ok(chord) => chord, + Err(e) => { + dropped.push(e); + continue; + } }; - let action = ActionId::from_name(name) - .ok_or_else(|| format!("line {n}: unknown action {name:?}"))?; - let chord = Chord::parse(chord, n)?; // One stroke, one meaning: the second line to claim it would be the - // dead one, and which of them died would depend on line order. + // dead one, and which of them died would depend on line order. The + // first line keeps the stroke, which is the order the file reads in. if let Some(held) = bindings.iter().find(|b| b.chord == chord) { - return Err(format!( + dropped.push(format!( "line {n}: {} is already {}'s", chord.text(), held.action.name() )); + continue; } bindings.push(Binding { action, chord }); } - Ok(Keymap { bindings }) + Ok((Keymap { bindings }, dropped)) } #[cfg(test)] @@ -637,6 +677,14 @@ mod tests { } } + /// A file every line of which the parser could use -- what most assertions + /// are about. A dropped line here is a failure, not a warning. + fn whole(text: &str) -> Keymap { + let (keymap, dropped) = parse(text).expect("a keybindings file"); + assert!(dropped.is_empty(), "unexpected dropped lines: {dropped:?}"); + keymap + } + #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); @@ -689,55 +737,116 @@ mod tests { assert!(text.contains("cancel-export escape\n")); // Both directions: the file this writes is the file it reads back, and // a file read in comes out byte for byte as it went. - assert_eq!(parse(&text), Ok(Keymap::defaults())); - assert_eq!(emit(&parse(&text).unwrap()), text); + assert_eq!(whole(&text), Keymap::defaults()); + assert_eq!(emit(&whole(&text)), text); let handwritten = "edith-keys 1\nundo ctrl+z\nplay space\n"; - assert_eq!(emit(&parse(handwritten).unwrap()), handwritten); + assert_eq!(emit(&whole(handwritten)), handwritten); // A keymap that binds nothing is legal -- and unusable, which is the // user's business, not the parser's. - assert_eq!(parse("edith-keys 1\n").unwrap().entries(), &[]); + assert_eq!(whole("edith-keys 1\n").entries(), &[]); } #[test] fn every_refusal_names_its_line() { + // Only the first line refuses the whole file. let err = |text: &str| parse(text).unwrap_err(); assert_eq!(err(""), "line 1: not a keybindings file"); assert_eq!(err("nonsense\n"), "line 1: not a keybindings file"); assert_eq!(err("edith-keys 2\n"), "line 1: unsupported version 2"); + + // Every other kind of bad line costs that line and nothing else. + let dropped = |text: &str| parse(text).unwrap().1; assert_eq!( - err("edith-keys 1\nfly space\n"), - "line 2: unknown action \"fly\"" + dropped("edith-keys 1\nfly space\n"), + ["line 2: unknown action \"fly\""] ); assert_eq!( - err("edith-keys 1\nplay space\nplayspace\n"), - "line 3: \"playspace\" is not ` `" + dropped("edith-keys 1\nplay space\nplayspace\n"), + ["line 3: \"playspace\" is not ` `"] ); // An empty line is not optional whitespace, it is a line. assert_eq!( - err("edith-keys 1\n\n"), - "line 2: \"\" is not ` `" + dropped("edith-keys 1\n\n"), + ["line 2: \"\" is not ` `"] ); assert_eq!( - err("edith-keys 1\nplay ctrl+alt+x\n"), - "line 2: \"ctrl+alt+x\" is not a chord" + dropped("edith-keys 1\nplay ctrl+alt+x\n"), + ["line 2: \"ctrl+alt+x\" is not a chord"] ); assert_eq!( - err("edith-keys 1\nplay ctrl+\n"), - "line 2: \"ctrl+\" is not a chord" + dropped("edith-keys 1\nplay ctrl+\n"), + ["line 2: \"ctrl+\" is not a chord"] ); // gpui reports lowercase key names, so an uppercase one would simply - // never match -- refused rather than quietly dead. + // never match -- dropped rather than quietly dead. assert_eq!( - err("edith-keys 1\nplay X\n"), - "line 2: \"X\" is not a chord" + dropped("edith-keys 1\nplay X\n"), + ["line 2: \"X\" is not a chord"] ); - // The same stroke twice: whichever line lost would depend on order. + // The same stroke twice: whichever line lost would depend on order, so + // the second one is the one that goes. assert_eq!( - err("edith-keys 1\nplay space\ncut space\n"), - "line 3: space is already play's" + dropped("edith-keys 1\nplay space\ncut space\n"), + ["line 3: space is already play's"] ); } + /// The rebind data-loss path: one line the parser cannot use must not cost + /// the rebinds around it (a `capture` of shift+= wrote `play +`, and the + /// next load threw the whole file away and went back to the defaults). + #[test] + fn one_bad_line_costs_only_that_line() { + let text = "edith-keys 1\nplay +\nexport ctrl+w\ncut j\n"; + let (keymap, dropped) = parse(text).expect("the magic line is still good"); + assert_eq!(dropped, ["line 2: \"+\" is not a chord"]); + // The lines around it are in force, which is the whole point. + assert_eq!(keymap.lookup("w", true), Some(ActionId::Export)); + assert_eq!(keymap.lookup("j", false), Some(ActionId::Cut)); + // ...and the one that went is unbound, not silently something else. + assert_eq!(keymap.display(ActionId::Play), "unbound"); + // What survives still round-trips: the kept lines emit back as read. + assert_eq!(emit(&keymap), "edith-keys 1\nexport ctrl+w\ncut j\n"); + + // The notice names the line and the file, and the defaults do *not* + // take over -- that was the data loss. + let dir = std::env::temp_dir().join(format!("edith-keymap-drop-{}", std::process::id())); + let path = dir.join("edith").join("keybindings"); + std::fs::create_dir_all(path.parent().unwrap()).unwrap(); + std::fs::write(&path, text).unwrap(); + let (read, notice) = Keymap::load_from(&path); + assert_eq!(read, keymap); + let notice = notice.expect("a part-read file must say so"); + assert!(notice.contains("line 2:"), "{notice}"); + assert!(notice.contains("keybindings"), "{notice}"); + std::fs::remove_dir_all(&dir).ok(); + } + + /// The other half of the same bug: a stroke the file cannot spell is refused + /// at the capture, before it can ever be written. + #[test] + fn only_a_stroke_the_file_can_spell_is_bindable() { + for (key, ctrl) in [ + ("space", false), + ("=", false), + ("s", true), + ("escape", false), + ] { + assert!(chord(key, ctrl).bindable(), "{key}"); + } + // gpui's name for shift+=, and the grammar's own separator. + assert!(!chord("+", false).bindable()); + assert!(!chord("+", true).bindable()); + // The rest of what `Chord::parse` will not take back. + assert!(!chord("", false).bindable()); + assert!(!chord("X", false).bindable()); + assert!(!chord("page up", false).bindable()); + // A bindable chord is one `rebind_action` may keep: what it writes is + // what the next load reads, for every stroke that passes here. + let mut k = Keymap::defaults(); + k.rebind_action(ActionId::Play, chord("=", true)).unwrap(); + assert_eq!(whole(&emit(&k)), k); + } + #[test] fn rebinding_refuses_to_steal_another_actions_stroke() { let mut k = Keymap::defaults(); @@ -774,7 +883,7 @@ mod tests { // reading in that order too. let order: Vec<_> = k.entries().iter().map(|b| b.action).collect(); assert_eq!(order, ActionId::ALL.to_vec()); - assert_eq!(emit(&k), emit(&parse(&emit(&k)).unwrap())); + assert_eq!(emit(&k), emit(&whole(&emit(&k)))); // Every action is now single-bound, so the file is one line each. assert_eq!(k.entries().len(), ActionId::ALL.len()); } @@ -788,10 +897,7 @@ mod tests { assert_eq!(k.display(ActionId::Undo), "z or ctrl+z"); // The one key whose common name is not gpui's. assert_eq!(k.display(ActionId::CancelExport), "esc"); - assert_eq!( - parse("edith-keys 1\n").unwrap().display(ActionId::Cut), - "unbound" - ); + assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); // The label is the editor's column, and never the file's word for it. assert_eq!(ActionId::CancelExport.label(), "Cancel export"); assert_eq!(ActionId::ALL.len(), 20); @@ -819,11 +925,20 @@ mod tests { let (fresh, notice) = Keymap::load_from(&dir.join("nothing-here")); assert_eq!(fresh, Keymap::defaults()); assert_eq!(notice, None); - // A corrupt one names its line and still leaves a usable keymap. - std::fs::write(&path, "edith-keys 1\nplay ctrl+alt+x\n").unwrap(); + // A file that is not one at all falls back whole, and names its line. + std::fs::write(&path, "edith-keys 9\nplay space\n").unwrap(); let (fallback, notice) = Keymap::load_from(&path); assert_eq!(fallback, Keymap::defaults()); let notice = notice.expect("a refused file must say so"); + assert!(notice.contains("line 1:"), "{notice}"); + assert!(notice.contains("keybindings"), "{notice}"); + // One unusable line inside a good file costs that line only -- the + // defaults do not come back over the rebinds that read fine. + std::fs::write(&path, "edith-keys 1\nplay ctrl+alt+x\nexport ctrl+w\n").unwrap(); + let (kept, notice) = Keymap::load_from(&path); + assert_eq!(kept.lookup("w", true), Some(ActionId::Export)); + assert_eq!(kept.display(ActionId::Play), "unbound"); + let notice = notice.expect("a part-read file must say so"); assert!(notice.contains("line 2:"), "{notice}"); assert!(notice.contains("keybindings"), "{notice}"); // Saving over it is a whole replacement, not an edit. diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 71859ef..cea58d4 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -1226,6 +1226,17 @@ impl Player { key: key.to_string(), ctrl, }; + // Only a stroke the file can spell and read back as itself: gpui reports + // "+" for shift+=, which is the chord grammar's separator, so binding it + // would write a line the next load would have to drop. Refused here, in + // front of the user, rather than silently costing that binding later. + // The row keeps waiting, as it does for a stroke already taken. + if !chord.bindable() { + let text = format!("THAT KEY CANNOT BE BOUND — {}", chord.pretty()); + eprintln!("{text}"); + self.notice = Some(text.into()); + return; + } let text = match self.keymap.rebind_action(action, chord.clone()) { Ok(()) => { self.rebinding = None; diff --git a/crates/engine/src/edith.rs b/crates/engine/src/edith.rs index 48198d5..947bee0 100644 --- a/crates/engine/src/edith.rs +++ b/crates/engine/src/edith.rs @@ -341,7 +341,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { } let f = fields(rest, 2, "resolution", n)?; let (width, height) = (number(f[0], n)?, number(f[1], n)?); - if width == 0 || height == 0 { + // The same bound the keystroke has (`crate::is_resolution`): + // unbounded here, this line reached `open_black` and panicked + // the open with a capacity overflow. + if !crate::is_resolution(width, height) { return Err(format!("line {n}: {width}x{height} is not a picture").into()); } doc.resolution = Some((width, height)); diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 3acbafd..87b4314 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -46,6 +46,20 @@ pub fn is_audio(path: &std::path::Path) -> bool { }) } +/// The largest picture this engine composes onto, either way: 8K, which is where +/// a per-frame buffer stops being a sane thing to allocate. +pub const MAX_RESOLUTION: u32 = 7680; + +/// Whether a project resolution is a picture at all: not zero either way, and +/// not past [`MAX_RESOLUTION`]. Both doors ask -- the keystroke +/// ([`PlaybackSession::set_resolution`](playback::PlaybackSession::set_resolution)) +/// and the file ([`edith::load`]) -- so a hand-written `resolution` line cannot +/// reach an allocation a keypress could not, which is how `4294967295` used to +/// panic the open with a capacity overflow. +pub fn is_resolution(width: u32, height: u32) -> bool { + (1..=MAX_RESOLUTION).contains(&width) && (1..=MAX_RESOLUTION).contains(&height) +} + /// Boxed error; the engine has few failure modes and every one of them is fatal /// to the session, so a message is all a caller can act on. pub type Error = Box; diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 90853cd..6a8ab93 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -629,8 +629,7 @@ impl PlaybackSession { /// keypress rather than a `z`. Upgrade path is snapshotting it beside the /// lanes, which every existing snapshot site would then have to carry. pub fn set_resolution(&mut self, width: u32, height: u32) -> bool { - const MAX: u32 = 7680; - if width == 0 || height == 0 || width > MAX || height > MAX { + if !crate::is_resolution(width, height) { return false; } if (width, height) == (self.meta.width, self.meta.height) { diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 77a0d72..38804e8 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -994,28 +994,60 @@ impl Project { /// /// `V1` and `A1` and no other lane, because a take is one picture and one /// sound: copying it onto every lane there is would play the same audio - /// twice over (and leave an mp4 export with two tracks to copy). The room is - /// still opened everywhere, or the lanes it was not inserted into would slide - /// out of step with the ones it was. + /// twice over (and leave an mp4 export with two tracks to copy). A clip of a + /// source with no picture ([`crate::is_audio`]) reaches `A1` only -- on a + /// video lane it is a clip that decodes to nothing, and a save carrying one + /// does not open again. The room is still opened everywhere, or the lanes it + /// was not inserted into would slide out of step with the ones it was. /// /// Exactly one history snapshot, so one [`Project::undo`] takes it back. - /// Changes the timeline->source mapping: the caller must reseek. Refused - /// only for an empty `clip`, which the never-empty invariant forbids but the - /// public fields still allow a caller to build. + /// Changes the timeline->source mapping: the caller must reseek. Refused for + /// an empty `clip` and for one naming a source that is not there (both of + /// which the public fields let a caller build), and for a paste whose ripple + /// would push a clip past the last frame there is -- nothing is changed by + /// any of them. pub fn paste(&mut self, timeline_frame: u32, clip: Clip) -> bool { + let Some(source) = self.sources.get(clip.source) else { + return false; + }; if clip.out_frame <= clip.in_frame { return false; } - self.snapshot(); + let audio_only = crate::is_audio(&source.path); let at = timeline_frame.min(self.timeline_frames()); + let len = clip.len(); + // Room for it: `open_room` adds `len` to every start from `at` on, and a + // hand-written file may hold a clip that ends at the very last frame + // (`edith::check` permits `start + len == u32::MAX`). Refused here + // rather than wrapped there -- a wrapped start lands *behind* the clip + // it belongs after, which is an overlap no save will read back. + if at.checked_add(len).is_none() + || self + .lanes + .iter() + .flat_map(|l| &l.clips) + .any(|c| c.end() > at && c.end().checked_add(len).is_none()) + { + return false; + } + self.snapshot(); let clip = Clip { start: at, link: Some(self.new_link()), ..clip }; - let takes: Vec = [LaneKind::Video, LaneKind::Audio] - .into_iter() - .filter_map(|kind| self.index(Lane::new(kind, 0))) + // Only lanes that can play the source: a file with no picture belongs on + // an audio lane and nowhere else, exactly as `place_stream_at` decides + // it for an import. On a video lane it would decode to nothing, and the + // save it wrote would not open again. + let kinds: &[LaneKind] = if audio_only { + &[LaneKind::Audio] + } else { + &[LaneKind::Video, LaneKind::Audio] + }; + let takes: Vec = kinds + .iter() + .filter_map(|&kind| self.index(Lane::new(kind, 0))) .collect(); for (i, data) in self.lanes.iter_mut().enumerate() { open_room(&mut data.clips, at, clip.len()); @@ -1740,6 +1772,71 @@ mod tests { assert_eq!(p.clips().len(), 3); } + /// The data-loss paste: a clip of a source with no picture used to land on + /// `V1` as well as `A1`, where it decodes to nothing -- and the save that + /// carried it was refused on the way back in ("a box with a larger size"). + #[test] + fn a_paste_of_a_source_with_no_picture_stays_off_the_video_lane() { + let mut p = three(); + let wav = p.import("/nonexistent/song.wav", 0); + let copied = Clip { + source: wav, + ..PASTED + }; + assert!(p.paste(3, copied)); + // The room is opened on every lane, or the two would slide apart... + assert_eq!(p.timeline_frames(), 11); + assert_eq!( + shape(&p)[0], + vec![clip(0, 0, 3, 0), clip(5, 3, 5, 0), clip(7, 5, 9, 0)], + "the video lane got room and nothing else" + ); + // ...but the clip itself only reaches the lane that can play it. + assert_eq!( + shape(&p)[1], + vec![ + clip(0, 0, 3, 0), + clip(3, 100, 102, wav), + clip(5, 3, 5, 0), + clip(7, 5, 9, 0) + ] + ); + // A source with a picture is unchanged: still the grouped pair. + let mut p = three(); + assert!(p.paste(3, PASTED)); + assert_eq!(shape(&p)[0], shape(&p)[1]); + } + + /// A hand-written file may hold a clip that ends at the very last frame + /// (`edith::check` permits `start + len == u32::MAX`), and the ripple used + /// to wrap its start round to the front of the lane: an overlap in debug, a + /// project no reload would accept in release. + #[test] + fn a_paste_that_would_run_past_the_last_frame_is_refused() { + let far = clip(u32::MAX - 90, 0, 90, 0); + let parts = |c: Clip| { + Project::from_parts( + vec![Source::new(FILE, 0)], + two(vec![c], vec![c]), + Vec::new(), + Vec::new(), + ) + .expect("valid parts") + }; + let mut p = parts(far); + assert!(!p.paste(0, PASTED), "no room for the two frames it adds"); + assert_eq!(shape(&p)[0], vec![far], "a refusal changes nothing"); + assert!(!p.undo(), "...and pushes no history either"); + assert!( + !p.paste(u32::MAX, PASTED), + "appending has nowhere to go either: the timeline ends at the last frame" + ); + // With room for exactly those frames the same paste is taken. + let mut p = parts(clip(u32::MAX - 92, 0, 90, 0)); + assert!(p.paste(0, PASTED)); + assert_eq!(p.lane(Lane::V1)[1].end(), u32::MAX); + } + #[test] fn paste_undoes_in_one_step() { let mut p = three(); diff --git a/crates/engine/tests/audio_files.rs b/crates/engine/tests/audio_files.rs index 4129e35..6b180b2 100644 --- a/crates/engine/tests/audio_files.rs +++ b/crates/engine/tests/audio_files.rs @@ -245,3 +245,48 @@ fn a_song_survives_a_save_and_a_reload() { ); let _ = std::fs::remove_dir_all(&dir); } + +/// ...and the door the editor itself had onto that same broken project: a copy +/// of the song pasted from the clipboard used to land on `V1` as well as `A1`, +/// where it decodes to nothing -- and the save it wrote was refused on the way +/// back in. The paste is the plain UI path, so this is data loss with no +/// hand-editing anywhere in it. +#[test] +fn a_pasted_song_never_lands_on_the_video_lane() { + let dir = std::env::temp_dir().join(format!("ve_audio_paste_{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("scratch dir"); + let copy = |name: &str| { + let to = dir.join(name); + std::fs::copy(asset(name), &to).expect("copy the fixture"); + to + }; + + let mut session = open(copy("test_av.mp4")); + session.import(©("test_tone.flac")).expect("import"); + let song = session.lane_clips(Lane::A1)[1]; + let video_before = session.lane_clips(Lane::V1).to_vec(); + assert!(session.paste_at(0.0, song), "paste the copied song"); + + // The video lane got room and nothing else: the same clips, pushed along. + let video_after = session.lane_clips(Lane::V1).to_vec(); + assert_eq!(video_after.len(), video_before.len(), "no clip on V1"); + for (after, before) in video_after.iter().zip(&video_before) { + assert_eq!(after.source, before.source); + assert_eq!(after.start, before.start + song.len()); + } + // The audio lane is the one that gained it, at the playhead. + assert_eq!(session.lane_clips(Lane::A1).len(), 3); + assert_eq!(session.lane_clips(Lane::A1)[0].source, song.source); + + // And the save that follows reopens -- which is what the video-lane clip + // used to cost ("file contains a box with a larger size than it"). + let project = dir.join("pasted.edith"); + session.save_project(&project).expect("save"); + drop(session); + let reloaded = PlaybackSession::open_project(&project).expect("the save reopens"); + reloaded.set_gain(0.0); + assert_eq!(reloaded.lane_clips(Lane::A1).len(), 3); + assert_eq!(reloaded.lane_clips(Lane::V1).len(), video_after.len()); + let _ = std::fs::remove_dir_all(&dir); +} diff --git a/crates/engine/tests/saveload.rs b/crates/engine/tests/saveload.rs index 1af4134..308e03e 100644 --- a/crates/engine/tests/saveload.rs +++ b/crates/engine/tests/saveload.rs @@ -381,6 +381,18 @@ fn a_version_7_project_carries_a_resolution_and_fit_policies() { video 1 0 0 30 0 - - - fit\n", "resolution belongs once", ), + // Past 8K is refused by the same bound the keystroke has: unbounded, + // this line reached `open_black` and panicked on a capacity overflow. + ( + "edith 7\nresolution 4294967295 4294967295\nsource 0 test_av.mp4\n\ + video 1 0 0 30 0 - - - fit\n", + "4294967295x4294967295 is not a picture", + ), + ( + "edith 7\nresolution 7681 1080\nsource 0 test_av.mp4\n\ + video 1 0 0 30 0 - - - fit\n", + "7681x1080 is not a picture", + ), ( "edith 7\nresolution 960 720\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - squish\n", "not a fit policy",