LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Never crash: Render demo scenes at most at their own size
Michael Andersone1860067a688
diff --git a/crates/scenes/src/lib.rs b/crates/scenes/src/lib.rsindex 1004b2ea9..11fd8685d 100644--- a/crates/scenes/src/lib.rs+++ b/crates/scenes/src/lib.rs@@ -68,7 +68,7 @@ impl Scene {paint::render(self.kind, self.seed, w, h)}- /// Render fitting within `max_edge` on the long side.+ /// Render fitting within `max_edge` on the long side (at most the scene's own size).pub fn render_fit(&self, max_edge: usize) -> Rgb32f {let (w, h) = self.fit(max_edge);self.render(w, h)@@ -81,6 +81,9 @@ impl Scene {}fn fit(&self, max_edge: usize) -> (usize, usize) {+ // never past the scene's own size: that is a demo photo's full resolution, and a size+ // from a damaged catalog (a width of 4294967295) asked for more memory than exists+ let max_edge = max_edge.min(self.width.max(self.height).max(1) as usize);let a = self.aspect();let (w, h) = if a >= 1.0 { (max_edge, (max_edge as f32 / a).round() as usize) } else { ((max_edge as f32 * a).round() as usize, max_edge) };(w.max(1), h.max(1))@@ -205,6 +208,18 @@ mod tests {}}+ /// Found by fuzzing catalog snapshots: a demo photo whose width read 4294967295 asked its scene+ /// for a render that size, and the pixel buffer's size overflowed (a panic on the render+ /// thread). A scene renders at most at its own size, which is the photo's full resolution.+ #[test]+ fn a_scene_renders_at_most_at_its_own_size() {+ let mut s = demo_library().remove(0);+ (s.width, s.height) = (40, 30);+ let img = s.render_fit(usize::MAX);+ assert_eq!((img.width, img.height), (40, 30));+ assert_eq!(s.fit(20), (20, 15), "smaller sizes as asked");+ }+#[test]fn sunsets_have_highlight_headroom() {let lib = demo_library();diff --git a/docs/whats-new.md b/docs/whats-new.mdindex b5c2ac68c..29caeb7b8 100644--- a/docs/whats-new.md+++ b/docs/whats-new.md@@ -2,6 +2,10 @@## 2026-10-13+### Reliability+- A demo photo whose stored size was damaged (a width of 4294967295) is rendered at its own size instead of+ one that overflows.+### Slider drags on large raws- Dragging a slider no longer re-renders the edited photo's filmstrip thumbnail on every frame; it follows once youlet go. On a 64 MP raw the first of those renders decoded the whole file again, which held up the loupe's