You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pantry expiring panics on a large --days value #428
cook pantry expiring --days N panics for large N instead of reporting an error or saturating.
Reproduction
cook pantry expiring -d 4294967295
Cause
src/pantry.rs:
let today = Local::now().date_naive();let threshold_date = today + chrono::Duration::days(args.daysasi64);
--days is a u32, and chrono's Add<Duration> for NaiveDate panics on out-of-range results rather than returning an error. Any value large enough to push the date past NaiveDate's representable range aborts the process.
Impact
Low severity — it needs an absurd --days value, so it is unlikely to be hit accidentally. But a panic is never the right response to a command-line argument, and the message a user sees is a Rust backtrace rather than anything actionable.
Suggested direction
Use checked_add_signed and either saturate at NaiveDate::MAX (every item is "expiring" within a window that large, which is arguably the right answer) or reject the value with a clear message.
Noticed while extracting the pantry queries into a library crate; that branch saturates, since a library must not panic on a caller-supplied number — a panic crossing a NAPI boundary into JavaScript is considerably worse than one in a CLI.
Fixed. Core saturates at NaiveDate::MAX (from #434); #444 fixed the copy in the server handler (fd36745), which was more exposed than the CLI path since days comes straight off the query string — an out-of-range value took down the request handler rather than a one-shot process.
Activity
dubadub commentedon Aug 14, 2026
Fixed. Core saturates at
NaiveDate::MAX(from #434); #444 fixed the copy in the server handler (fd36745), which was more exposed than the CLI path sincedayscomes straight off the query string — an out-of-range value took down the request handler rather than a one-shot process.stats.rsuses a literal 7-day window, which cannot run off the end of the calendar, so it is left as it is.fix(server): saturate the pantry expiring threshold instead of panicking