Reject out-of-range start in photo.rename and photo.renamePreview

Found while testing crates/engine/src/rename.rs:919 (start parsed at crates/engine/src/cmd/manage.rs:12)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-16 16:21:24 +02:00
co-authored by Claude Haiku 5.5
parent f34c7a8a89
commit 312dd04830
3 changed files with 29 additions and 3 deletions
+7 -2
View File
@@ -9,8 +9,13 @@ use crate::Result;
fn rename_args(s: &crate::Session, p: &Value, c: &str) -> Result<(Vec<lightcraft_catalog::PhotoId>, String, usize)> {
let template = str_param(p, "template").ok_or_else(|| bad(c, "missing `template`"))?.to_string();
let start = p.get("start").and_then(Value::as_u64).unwrap_or(1) as usize;
Ok((s.targets(p)?, template, start))
let start = p.get("start").and_then(Value::as_u64).unwrap_or(1);
let ids = s.targets(p)?;
// every number of the sequence `start..start + n` must fit
let last = start.checked_add((ids.len() as u64).saturating_sub(1));
let start = last.and_then(|l| usize::try_from(l).ok()).and_then(|_| usize::try_from(start).ok());
let start = start.ok_or_else(|| bad(c, "start out of range"))?;
Ok((ids, template, start))
}
/// A named set of colour-label names (red, yellow, green, blue, purple; empty = the colour's name).