forge
Explore
Log in

Don't you dare go Hollow

Paste respects lane kinds

Browse files at this commit

11603ec0d159c2d117c2064eb85d284e4c4e80c2Ahmet Kaan GümüşParent: cd9f0df
  • fix
    • paste respects lane kinds
    • bounds and rebind capture hardened
Show full message
🐛 fix(engine,ui): paste respects lane kinds; bounds and rebind capture hardened

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.rsmodified+155 -40
@@ -14,10 +14,12 @@
1414 //! compares against that string and nothing translates in between. What a
1515 //! *person* reads is [`Keymap::display`]'s business, and only there.
1616 //!
17-//! The parser is strict and every refusal names its 1-based line, like the
18-//! project file: this file is generated by the keybindings editor, so a line it
19-//! did not generate is a corrupt file rather than a dialect. A missing file is
20-//! not corrupt -- it means nobody has changed a key yet, and the defaults stand.
17+//! The parser is strict and everything it cannot use names its 1-based line,
18+//! like the project file. Only the first line refuses the whole file: a binding
19+//! line the parser cannot use is *dropped*, named in the notice, and every other
20+//! line still stands -- one unusable line is not a reason to throw away the
21+//! rebinds around it. A missing file is not corrupt either -- it means nobody
22+//! has changed a key yet, and the defaults stand.
2123 //!
2224 //! Writing mirrors `engine::edith::save`: `.part`, fsync, rename, directory
2325 //! fsync, so an interrupted save cannot cost the bindings that were already
@@ -323,6 +325,16 @@ impl Chord {
323325 }
324326 }
325327
328+ /// Whether the file can carry this stroke and read it back as itself. gpui
329+ /// reports strokes this format cannot spell -- shift+= arrives as the key
330+ /// `"+"`, which is the chord grammar's own separator -- and binding one
331+ /// would write a line the next load has to drop. Asked before a capture is
332+ /// taken, so a stroke that cannot be saved is refused while the user is
333+ /// still looking at the row.
334+ pub fn bindable(&self) -> bool {
335+ Chord::parse(&self.text(), 0).is_ok_and(|round_trip| round_trip == *self)
336+ }
337+
326338 /// Strict: exactly one optional `ctrl+` and then a key gpui could have
327339 /// reported. A spelling this cannot emit back unchanged is refused rather
328340 /// than normalised, because the round-trip is what makes the file editable
@@ -504,7 +516,17 @@ impl Keymap {
504516 }
505517 };
506518 match parse(&text) {
507- Ok(keymap) => (keymap, None),
519+ Ok((keymap, dropped)) if dropped.is_empty() => (keymap, None),
520+ // The lines it could use are in force; the ones it could not are
521+ // named, and only those are lost.
522+ Ok((keymap, dropped)) => (
523+ keymap,
524+ Some(format!(
525+ "KEYBINDINGS PART-READ — {}, {} — those strokes are unbound",
526+ path.display(),
527+ dropped.join("; ")
528+ )),
529+ ),
508530 Err(e) => (
509531 Self::defaults(),
510532 Some(format!(
@@ -590,7 +612,13 @@ fn emit(keymap: &Keymap) -> String {
590612 out
591613 }
592614
593-fn parse(text: &str) -> Result<Keymap, String> {
615+/// The magic line is the whole of what makes this a keybindings file, so it is
616+/// the only thing refused outright. A *binding* line this parser cannot use is
617+/// dropped instead, and named in the returned warnings: one unusable line used
618+/// to cost every other rebind in the file, which is the user's data. What
619+/// survives is still exactly what emits back, so the by-hand round-trip holds
620+/// for every line that is kept.
621+fn parse(text: &str) -> Result<(Keymap, Vec<String>), String> {
594622 // One trailing newline terminates the last line rather than starting an
595623 // empty one; a second is an empty line and is refused below.
596624 let body = text.strip_suffix('\n').unwrap_or(text);
@@ -604,26 +632,38 @@ fn parse(text: &str) -> Result<Keymap, String> {
604632 }
605633
606634 let mut bindings: Vec<Binding> = Vec::new();
635+ let mut dropped: Vec<String> = Vec::new();
607636 for (i, line) in lines {
608637 let n = i + 1;
609638 let Some((name, chord)) = line.split_once(' ') else {
610- return Err(format!("line {n}: {line:?} is not `<action> <chord>`"));
639+ dropped.push(format!("line {n}: {line:?} is not `<action> <chord>`"));
640+ continue;
641+ };
642+ let Some(action) = ActionId::from_name(name) else {
643+ dropped.push(format!("line {n}: unknown action {name:?}"));
644+ continue;
645+ };
646+ let chord = match Chord::parse(chord, n) {
647+ Ok(chord) => chord,
648+ Err(e) => {
649+ dropped.push(e);
650+ continue;
651+ }
611652 };
612- let action = ActionId::from_name(name)
613- .ok_or_else(|| format!("line {n}: unknown action {name:?}"))?;
614- let chord = Chord::parse(chord, n)?;
615653 // One stroke, one meaning: the second line to claim it would be the
616- // dead one, and which of them died would depend on line order.
654+ // dead one, and which of them died would depend on line order. The
655+ // first line keeps the stroke, which is the order the file reads in.
617656 if let Some(held) = bindings.iter().find(|b| b.chord == chord) {
618- return Err(format!(
657+ dropped.push(format!(
619658 "line {n}: {} is already {}'s",
620659 chord.text(),
621660 held.action.name()
622661 ));
662+ continue;
623663 }
624664 bindings.push(Binding { action, chord });
625665 }
626- Ok(Keymap { bindings })
666+ Ok((Keymap { bindings }, dropped))
627667 }
628668
629669 #[cfg(test)]
@@ -637,6 +677,14 @@ mod tests {
637677 }
638678 }
639679
680+ /// A file every line of which the parser could use -- what most assertions
681+ /// are about. A dropped line here is a failure, not a warning.
682+ fn whole(text: &str) -> Keymap {
683+ let (keymap, dropped) = parse(text).expect("a keybindings file");
684+ assert!(dropped.is_empty(), "unexpected dropped lines: {dropped:?}");
685+ keymap
686+ }
687+
640688 #[test]
641689 fn every_default_stroke_reaches_its_action() {
642690 let k = Keymap::defaults();
@@ -689,55 +737,116 @@ mod tests {
689737 assert!(text.contains("cancel-export escape\n"));
690738 // Both directions: the file this writes is the file it reads back, and
691739 // a file read in comes out byte for byte as it went.
692- assert_eq!(parse(&text), Ok(Keymap::defaults()));
693- assert_eq!(emit(&parse(&text).unwrap()), text);
740+ assert_eq!(whole(&text), Keymap::defaults());
741+ assert_eq!(emit(&whole(&text)), text);
694742 let handwritten = "edith-keys 1\nundo ctrl+z\nplay space\n";
695- assert_eq!(emit(&parse(handwritten).unwrap()), handwritten);
743+ assert_eq!(emit(&whole(handwritten)), handwritten);
696744 // A keymap that binds nothing is legal -- and unusable, which is the
697745 // user's business, not the parser's.
698- assert_eq!(parse("edith-keys 1\n").unwrap().entries(), &[]);
746+ assert_eq!(whole("edith-keys 1\n").entries(), &[]);
699747 }
700748
701749 #[test]
702750 fn every_refusal_names_its_line() {
751+ // Only the first line refuses the whole file.
703752 let err = |text: &str| parse(text).unwrap_err();
704753 assert_eq!(err(""), "line 1: not a keybindings file");
705754 assert_eq!(err("nonsense\n"), "line 1: not a keybindings file");
706755 assert_eq!(err("edith-keys 2\n"), "line 1: unsupported version 2");
756+
757+ // Every other kind of bad line costs that line and nothing else.
758+ let dropped = |text: &str| parse(text).unwrap().1;
707759 assert_eq!(
708- err("edith-keys 1\nfly space\n"),
709- "line 2: unknown action \"fly\""
760+ dropped("edith-keys 1\nfly space\n"),
761+ ["line 2: unknown action \"fly\""]
710762 );
711763 assert_eq!(
712- err("edith-keys 1\nplay space\nplayspace\n"),
713- "line 3: \"playspace\" is not `<action> <chord>`"
764+ dropped("edith-keys 1\nplay space\nplayspace\n"),
765+ ["line 3: \"playspace\" is not `<action> <chord>`"]
714766 );
715767 // An empty line is not optional whitespace, it is a line.
716768 assert_eq!(
717- err("edith-keys 1\n\n"),
718- "line 2: \"\" is not `<action> <chord>`"
769+ dropped("edith-keys 1\n\n"),
770+ ["line 2: \"\" is not `<action> <chord>`"]
719771 );
720772 assert_eq!(
721- err("edith-keys 1\nplay ctrl+alt+x\n"),
722- "line 2: \"ctrl+alt+x\" is not a chord"
773+ dropped("edith-keys 1\nplay ctrl+alt+x\n"),
774+ ["line 2: \"ctrl+alt+x\" is not a chord"]
723775 );
724776 assert_eq!(
725- err("edith-keys 1\nplay ctrl+\n"),
726- "line 2: \"ctrl+\" is not a chord"
777+ dropped("edith-keys 1\nplay ctrl+\n"),
778+ ["line 2: \"ctrl+\" is not a chord"]
727779 );
728780 // gpui reports lowercase key names, so an uppercase one would simply
729- // never match -- refused rather than quietly dead.
781+ // never match -- dropped rather than quietly dead.
730782 assert_eq!(
731- err("edith-keys 1\nplay X\n"),
732- "line 2: \"X\" is not a chord"
783+ dropped("edith-keys 1\nplay X\n"),
784+ ["line 2: \"X\" is not a chord"]
733785 );
734- // The same stroke twice: whichever line lost would depend on order.
786+ // The same stroke twice: whichever line lost would depend on order, so
787+ // the second one is the one that goes.
735788 assert_eq!(
736- err("edith-keys 1\nplay space\ncut space\n"),
737- "line 3: space is already play's"
789+ dropped("edith-keys 1\nplay space\ncut space\n"),
790+ ["line 3: space is already play's"]
738791 );
739792 }
740793
794+ /// The rebind data-loss path: one line the parser cannot use must not cost
795+ /// the rebinds around it (a `capture` of shift+= wrote `play +`, and the
796+ /// next load threw the whole file away and went back to the defaults).
797+ #[test]
798+ fn one_bad_line_costs_only_that_line() {
799+ let text = "edith-keys 1\nplay +\nexport ctrl+w\ncut j\n";
800+ let (keymap, dropped) = parse(text).expect("the magic line is still good");
801+ assert_eq!(dropped, ["line 2: \"+\" is not a chord"]);
802+ // The lines around it are in force, which is the whole point.
803+ assert_eq!(keymap.lookup("w", true), Some(ActionId::Export));
804+ assert_eq!(keymap.lookup("j", false), Some(ActionId::Cut));
805+ // ...and the one that went is unbound, not silently something else.
806+ assert_eq!(keymap.display(ActionId::Play), "unbound");
807+ // What survives still round-trips: the kept lines emit back as read.
808+ assert_eq!(emit(&keymap), "edith-keys 1\nexport ctrl+w\ncut j\n");
809+
810+ // The notice names the line and the file, and the defaults do *not*
811+ // take over -- that was the data loss.
812+ let dir = std::env::temp_dir().join(format!("edith-keymap-drop-{}", std::process::id()));
813+ let path = dir.join("edith").join("keybindings");
814+ std::fs::create_dir_all(path.parent().unwrap()).unwrap();
815+ std::fs::write(&path, text).unwrap();
816+ let (read, notice) = Keymap::load_from(&path);
817+ assert_eq!(read, keymap);
818+ let notice = notice.expect("a part-read file must say so");
819+ assert!(notice.contains("line 2:"), "{notice}");
820+ assert!(notice.contains("keybindings"), "{notice}");
821+ std::fs::remove_dir_all(&dir).ok();
822+ }
823+
824+ /// The other half of the same bug: a stroke the file cannot spell is refused
825+ /// at the capture, before it can ever be written.
826+ #[test]
827+ fn only_a_stroke_the_file_can_spell_is_bindable() {
828+ for (key, ctrl) in [
829+ ("space", false),
830+ ("=", false),
831+ ("s", true),
832+ ("escape", false),
833+ ] {
834+ assert!(chord(key, ctrl).bindable(), "{key}");
835+ }
836+ // gpui's name for shift+=, and the grammar's own separator.
837+ assert!(!chord("+", false).bindable());
838+ assert!(!chord("+", true).bindable());
839+ // The rest of what `Chord::parse` will not take back.
840+ assert!(!chord("", false).bindable());
841+ assert!(!chord("X", false).bindable());
842+ assert!(!chord("page up", false).bindable());
843+ // A bindable chord is one `rebind_action` may keep: what it writes is
844+ // what the next load reads, for every stroke that passes here.
845+ let mut k = Keymap::defaults();
846+ k.rebind_action(ActionId::Play, chord("=", true)).unwrap();
847+ assert_eq!(whole(&emit(&k)), k);
848+ }
849+
741850 #[test]
742851 fn rebinding_refuses_to_steal_another_actions_stroke() {
743852 let mut k = Keymap::defaults();
@@ -774,7 +883,7 @@ mod tests {
774883 // reading in that order too.
775884 let order: Vec<_> = k.entries().iter().map(|b| b.action).collect();
776885 assert_eq!(order, ActionId::ALL.to_vec());
777- assert_eq!(emit(&k), emit(&parse(&emit(&k)).unwrap()));
886+ assert_eq!(emit(&k), emit(&whole(&emit(&k))));
778887 // Every action is now single-bound, so the file is one line each.
779888 assert_eq!(k.entries().len(), ActionId::ALL.len());
780889 }
@@ -788,10 +897,7 @@ mod tests {
788897 assert_eq!(k.display(ActionId::Undo), "z or ctrl+z");
789898 // The one key whose common name is not gpui's.
790899 assert_eq!(k.display(ActionId::CancelExport), "esc");
791- assert_eq!(
792- parse("edith-keys 1\n").unwrap().display(ActionId::Cut),
793- "unbound"
794- );
900+ assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound");
795901 // The label is the editor's column, and never the file's word for it.
796902 assert_eq!(ActionId::CancelExport.label(), "Cancel export");
797903 assert_eq!(ActionId::ALL.len(), 20);
@@ -819,11 +925,20 @@ mod tests {
819925 let (fresh, notice) = Keymap::load_from(&dir.join("nothing-here"));
820926 assert_eq!(fresh, Keymap::defaults());
821927 assert_eq!(notice, None);
822- // A corrupt one names its line and still leaves a usable keymap.
823- std::fs::write(&path, "edith-keys 1\nplay ctrl+alt+x\n").unwrap();
928+ // A file that is not one at all falls back whole, and names its line.
929+ std::fs::write(&path, "edith-keys 9\nplay space\n").unwrap();
824930 let (fallback, notice) = Keymap::load_from(&path);
825931 assert_eq!(fallback, Keymap::defaults());
826932 let notice = notice.expect("a refused file must say so");
933+ assert!(notice.contains("line 1:"), "{notice}");
934+ assert!(notice.contains("keybindings"), "{notice}");
935+ // One unusable line inside a good file costs that line only -- the
936+ // defaults do not come back over the rebinds that read fine.
937+ std::fs::write(&path, "edith-keys 1\nplay ctrl+alt+x\nexport ctrl+w\n").unwrap();
938+ let (kept, notice) = Keymap::load_from(&path);
939+ assert_eq!(kept.lookup("w", true), Some(ActionId::Export));
940+ assert_eq!(kept.display(ActionId::Play), "unbound");
941+ let notice = notice.expect("a part-read file must say so");
827942 assert!(notice.contains("line 2:"), "{notice}");
828943 assert!(notice.contains("keybindings"), "{notice}");
829944 // Saving over it is a whole replacement, not an edit.
crates/app/src/main.rsmodified+11 -0
@@ -1226,6 +1226,17 @@ impl Player {
12261226 key: key.to_string(),
12271227 ctrl,
12281228 };
1229+ // Only a stroke the file can spell and read back as itself: gpui reports
1230+ // "+" for shift+=, which is the chord grammar's separator, so binding it
1231+ // would write a line the next load would have to drop. Refused here, in
1232+ // front of the user, rather than silently costing that binding later.
1233+ // The row keeps waiting, as it does for a stroke already taken.
1234+ if !chord.bindable() {
1235+ let text = format!("THAT KEY CANNOT BE BOUND — {}", chord.pretty());
1236+ eprintln!("{text}");
1237+ self.notice = Some(text.into());
1238+ return;
1239+ }
12291240 let text = match self.keymap.rebind_action(action, chord.clone()) {
12301241 Ok(()) => {
12311242 self.rebinding = None;
crates/engine/src/edith.rsmodified+4 -1
@@ -341,7 +341,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
341341 }
342342 let f = fields(rest, 2, "resolution", n)?;
343343 let (width, height) = (number(f[0], n)?, number(f[1], n)?);
344- if width == 0 || height == 0 {
344+ // The same bound the keystroke has (`crate::is_resolution`):
345+ // unbounded here, this line reached `open_black` and panicked
346+ // the open with a capacity overflow.
347+ if !crate::is_resolution(width, height) {
345348 return Err(format!("line {n}: {width}x{height} is not a picture").into());
346349 }
347350 doc.resolution = Some((width, height));
crates/engine/src/lib.rsmodified+14 -0
@@ -46,6 +46,20 @@ pub fn is_audio(path: &std::path::Path) -> bool {
4646 })
4747 }
4848
49+/// The largest picture this engine composes onto, either way: 8K, which is where
50+/// a per-frame buffer stops being a sane thing to allocate.
51+pub const MAX_RESOLUTION: u32 = 7680;
52+
53+/// Whether a project resolution is a picture at all: not zero either way, and
54+/// not past [`MAX_RESOLUTION`]. Both doors ask -- the keystroke
55+/// ([`PlaybackSession::set_resolution`](playback::PlaybackSession::set_resolution))
56+/// and the file ([`edith::load`]) -- so a hand-written `resolution` line cannot
57+/// reach an allocation a keypress could not, which is how `4294967295` used to
58+/// panic the open with a capacity overflow.
59+pub fn is_resolution(width: u32, height: u32) -> bool {
60+ (1..=MAX_RESOLUTION).contains(&width) && (1..=MAX_RESOLUTION).contains(&height)
61+}
62+
4963 /// Boxed error; the engine has few failure modes and every one of them is fatal
5064 /// to the session, so a message is all a caller can act on.
5165 pub type Error = Box<dyn std::error::Error + Send + Sync>;
crates/engine/src/playback.rsmodified+1 -2
@@ -629,8 +629,7 @@ impl PlaybackSession {
629629 /// keypress rather than a `z`. Upgrade path is snapshotting it beside the
630630 /// lanes, which every existing snapshot site would then have to carry.
631631 pub fn set_resolution(&mut self, width: u32, height: u32) -> bool {
632- const MAX: u32 = 7680;
633- if width == 0 || height == 0 || width > MAX || height > MAX {
632+ if !crate::is_resolution(width, height) {
634633 return false;
635634 }
636635 if (width, height) == (self.meta.width, self.meta.height) {
crates/engine/src/project.rsmodified+107 -10
@@ -994,28 +994,60 @@ impl Project {
994994 ///
995995 /// `V1` and `A1` and no other lane, because a take is one picture and one
996996 /// sound: copying it onto every lane there is would play the same audio
997- /// twice over (and leave an mp4 export with two tracks to copy). The room is
998- /// still opened everywhere, or the lanes it was not inserted into would slide
999- /// out of step with the ones it was.
997+ /// twice over (and leave an mp4 export with two tracks to copy). A clip of a
998+ /// source with no picture ([`crate::is_audio`]) reaches `A1` only -- on a
999+ /// video lane it is a clip that decodes to nothing, and a save carrying one
1000+ /// does not open again. The room is still opened everywhere, or the lanes it
1001+ /// was not inserted into would slide out of step with the ones it was.
10001002 ///
10011003 /// Exactly one history snapshot, so one [`Project::undo`] takes it back.
1002- /// Changes the timeline->source mapping: the caller must reseek. Refused
1003- /// only for an empty `clip`, which the never-empty invariant forbids but the
1004- /// public fields still allow a caller to build.
1004+ /// Changes the timeline->source mapping: the caller must reseek. Refused for
1005+ /// an empty `clip` and for one naming a source that is not there (both of
1006+ /// which the public fields let a caller build), and for a paste whose ripple
1007+ /// would push a clip past the last frame there is -- nothing is changed by
1008+ /// any of them.
10051009 pub fn paste(&mut self, timeline_frame: u32, clip: Clip) -> bool {
1010+ let Some(source) = self.sources.get(clip.source) else {
1011+ return false;
1012+ };
10061013 if clip.out_frame <= clip.in_frame {
10071014 return false;
10081015 }
1009- self.snapshot();
1016+ let audio_only = crate::is_audio(&source.path);
10101017 let at = timeline_frame.min(self.timeline_frames());
1018+ let len = clip.len();
1019+ // Room for it: `open_room` adds `len` to every start from `at` on, and a
1020+ // hand-written file may hold a clip that ends at the very last frame
1021+ // (`edith::check` permits `start + len == u32::MAX`). Refused here
1022+ // rather than wrapped there -- a wrapped start lands *behind* the clip
1023+ // it belongs after, which is an overlap no save will read back.
1024+ if at.checked_add(len).is_none()
1025+ || self
1026+ .lanes
1027+ .iter()
1028+ .flat_map(|l| &l.clips)
1029+ .any(|c| c.end() > at && c.end().checked_add(len).is_none())
1030+ {
1031+ return false;
1032+ }
1033+ self.snapshot();
10111034 let clip = Clip {
10121035 start: at,
10131036 link: Some(self.new_link()),
10141037 ..clip
10151038 };
1016- let takes: Vec<usize> = [LaneKind::Video, LaneKind::Audio]
1017- .into_iter()
1018- .filter_map(|kind| self.index(Lane::new(kind, 0)))
1039+ // Only lanes that can play the source: a file with no picture belongs on
1040+ // an audio lane and nowhere else, exactly as `place_stream_at` decides
1041+ // it for an import. On a video lane it would decode to nothing, and the
1042+ // save it wrote would not open again.
1043+ let kinds: &[LaneKind] = if audio_only {
1044+ &[LaneKind::Audio]
1045+ } else {
1046+ &[LaneKind::Video, LaneKind::Audio]
1047+ };
1048+ let takes: Vec<usize> = kinds
1049+ .iter()
1050+ .filter_map(|&kind| self.index(Lane::new(kind, 0)))
10191051 .collect();
10201052 for (i, data) in self.lanes.iter_mut().enumerate() {
10211053 open_room(&mut data.clips, at, clip.len());
@@ -1740,6 +1772,71 @@ mod tests {
17401772 assert_eq!(p.clips().len(), 3);
17411773 }
17421774
1775+ /// The data-loss paste: a clip of a source with no picture used to land on
1776+ /// `V1` as well as `A1`, where it decodes to nothing -- and the save that
1777+ /// carried it was refused on the way back in ("a box with a larger size").
1778+ #[test]
1779+ fn a_paste_of_a_source_with_no_picture_stays_off_the_video_lane() {
1780+ let mut p = three();
1781+ let wav = p.import("/nonexistent/song.wav", 0);
1782+ let copied = Clip {
1783+ source: wav,
1784+ ..PASTED
1785+ };
1786+ assert!(p.paste(3, copied));
1787+ // The room is opened on every lane, or the two would slide apart...
1788+ assert_eq!(p.timeline_frames(), 11);
1789+ assert_eq!(
1790+ shape(&p)[0],
1791+ vec![clip(0, 0, 3, 0), clip(5, 3, 5, 0), clip(7, 5, 9, 0)],
1792+ "the video lane got room and nothing else"
1793+ );
1794+ // ...but the clip itself only reaches the lane that can play it.
1795+ assert_eq!(
1796+ shape(&p)[1],
1797+ vec![
1798+ clip(0, 0, 3, 0),
1799+ clip(3, 100, 102, wav),
1800+ clip(5, 3, 5, 0),
1801+ clip(7, 5, 9, 0)
1802+ ]
1803+ );
1804+ // A source with a picture is unchanged: still the grouped pair.
1805+ let mut p = three();
1806+ assert!(p.paste(3, PASTED));
1807+ assert_eq!(shape(&p)[0], shape(&p)[1]);
1808+ }
1809+
1810+ /// A hand-written file may hold a clip that ends at the very last frame
1811+ /// (`edith::check` permits `start + len == u32::MAX`), and the ripple used
1812+ /// to wrap its start round to the front of the lane: an overlap in debug, a
1813+ /// project no reload would accept in release.
1814+ #[test]
1815+ fn a_paste_that_would_run_past_the_last_frame_is_refused() {
1816+ let far = clip(u32::MAX - 90, 0, 90, 0);
1817+ let parts = |c: Clip| {
1818+ Project::from_parts(
1819+ vec![Source::new(FILE, 0)],
1820+ two(vec![c], vec![c]),
1821+ Vec::new(),
1822+ Vec::new(),
1823+ )
1824+ .expect("valid parts")
1825+ };
1826+ let mut p = parts(far);
1827+ assert!(!p.paste(0, PASTED), "no room for the two frames it adds");
1828+ assert_eq!(shape(&p)[0], vec![far], "a refusal changes nothing");
1829+ assert!(!p.undo(), "...and pushes no history either");
1830+ assert!(
1831+ !p.paste(u32::MAX, PASTED),
1832+ "appending has nowhere to go either: the timeline ends at the last frame"
1833+ );
1834+ // With room for exactly those frames the same paste is taken.
1835+ let mut p = parts(clip(u32::MAX - 92, 0, 90, 0));
1836+ assert!(p.paste(0, PASTED));
1837+ assert_eq!(p.lane(Lane::V1)[1].end(), u32::MAX);
1838+ }
1839+
17431840 #[test]
17441841 fn paste_undoes_in_one_step() {
17451842 let mut p = three();
crates/engine/tests/audio_files.rsmodified+45 -0
@@ -245,3 +245,48 @@ fn a_song_survives_a_save_and_a_reload() {
245245 );
246246 let _ = std::fs::remove_dir_all(&dir);
247247 }
248+
249+/// ...and the door the editor itself had onto that same broken project: a copy
250+/// of the song pasted from the clipboard used to land on `V1` as well as `A1`,
251+/// where it decodes to nothing -- and the save it wrote was refused on the way
252+/// back in. The paste is the plain UI path, so this is data loss with no
253+/// hand-editing anywhere in it.
254+#[test]
255+fn a_pasted_song_never_lands_on_the_video_lane() {
256+ let dir = std::env::temp_dir().join(format!("ve_audio_paste_{}", std::process::id()));
257+ let _ = std::fs::remove_dir_all(&dir);
258+ std::fs::create_dir_all(&dir).expect("scratch dir");
259+ let copy = |name: &str| {
260+ let to = dir.join(name);
261+ std::fs::copy(asset(name), &to).expect("copy the fixture");
262+ to
263+ };
264+
265+ let mut session = open(copy("test_av.mp4"));
266+ session.import(&copy("test_tone.flac")).expect("import");
267+ let song = session.lane_clips(Lane::A1)[1];
268+ let video_before = session.lane_clips(Lane::V1).to_vec();
269+ assert!(session.paste_at(0.0, song), "paste the copied song");
270+
271+ // The video lane got room and nothing else: the same clips, pushed along.
272+ let video_after = session.lane_clips(Lane::V1).to_vec();
273+ assert_eq!(video_after.len(), video_before.len(), "no clip on V1");
274+ for (after, before) in video_after.iter().zip(&video_before) {
275+ assert_eq!(after.source, before.source);
276+ assert_eq!(after.start, before.start + song.len());
277+ }
278+ // The audio lane is the one that gained it, at the playhead.
279+ assert_eq!(session.lane_clips(Lane::A1).len(), 3);
280+ assert_eq!(session.lane_clips(Lane::A1)[0].source, song.source);
281+
282+ // And the save that follows reopens -- which is what the video-lane clip
283+ // used to cost ("file contains a box with a larger size than it").
284+ let project = dir.join("pasted.edith");
285+ session.save_project(&project).expect("save");
286+ drop(session);
287+ let reloaded = PlaybackSession::open_project(&project).expect("the save reopens");
288+ reloaded.set_gain(0.0);
289+ assert_eq!(reloaded.lane_clips(Lane::A1).len(), 3);
290+ assert_eq!(reloaded.lane_clips(Lane::V1).len(), video_after.len());
291+ let _ = std::fs::remove_dir_all(&dir);
292+}
crates/engine/tests/saveload.rsmodified+12 -0
@@ -381,6 +381,18 @@ fn a_version_7_project_carries_a_resolution_and_fit_policies() {
381381 video 1 0 0 30 0 - - - fit\n",
382382 "resolution belongs once",
383383 ),
384+ // Past 8K is refused by the same bound the keystroke has: unbounded,
385+ // this line reached `open_black` and panicked on a capacity overflow.
386+ (
387+ "edith 7\nresolution 4294967295 4294967295\nsource 0 test_av.mp4\n\
388+ video 1 0 0 30 0 - - - fit\n",
389+ "4294967295x4294967295 is not a picture",
390+ ),
391+ (
392+ "edith 7\nresolution 7681 1080\nsource 0 test_av.mp4\n\
393+ video 1 0 0 30 0 - - - fit\n",
394+ "7681x1080 is not a picture",
395+ ),
384396 (
385397 "edith 7\nresolution 960 720\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - squish\n",
386398 "not a fit policy",