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
id(web): parse_iso_timestamp accepts out-of-range dates — month 13, day 0/32, Feb 30, hour 25 and pre-1970 years all return plausible-but-wrong timestamps #756
parse_iso_timestamp in pkgs/id/src/web/routes.rs:148-201 — the parser behind classify_tag (routes.rs:125-141) for auto-<ISO date> backup tag names — performs no range validation on any component. Out-of-range values are silently rolled over into a different, plausible timestamp instead of returning None, and a pre-1970 year is clamped to the epoch. The resulting FileInfo.timestamp (routes.rs:714, second pass of the file-list builder) therefore shows/sorts an auto-backup under a date its name does not contain.
Evidence (verified this run)
The function was extracted verbatim from current main and run standalone (rustc -O, unmodified logic). The valid control matches the known epoch exactly:
Input
Result
Correct behaviour
2026-03-12T06:42:30Z
Some(1773297750)
✅ matches reference epoch
2026-13-01T00:00:00Z
Some(1798761600) (= 2027-01-01)
month 13 rolls into next year
2026-00-01T00:00:00Z
Some(1767225600) (= 2026-01-01)
month 0 silently becomes January
2026-03-00T00:00:00Z
Some(1772323200)
identical to 2026-03-01 — day 0 == day 1
2026-03-32T00:00:00Z
Some(1775001600) (= 2026-04-01)
day 32 rolls into April
2026-02-30T00:00:00Z
Some(1772409600) (= 2026-03-02)
Feb 30 rolls into March
2026-03-12T25:00:00Z
Some(1773363600)
hour 25 rolls into the next day
2026-03-12T00:60:00Z / T00:00:60Z
Some(...)
minute/second 60 roll over
1969-01-01T00:00:00Z
Some(0)
identical to the epoch — the 1970..year loop never runs and the date collapses to 1970-01-01
Contributing code:
routes.rs:165-168 — components are collected with filter_map(|p| p.parse().ok()), so only count is checked, never range.
routes.rs:182 — the month loop is capped only by the month_days array length, so month 13 accumulates a full year.
routes.rs:190 — day.saturating_sub(1) makes day 0 indistinguishable from day 1.
routes.rs:192 — hour * 3600 + min * 60 + sec accepts any hour/minute/second.
Related robustness note (same function): the days calculation loops for y in 1970..year with no upper bound, so a tag named e.g. auto-999999999-01-01T00:00:00Z makes the file-list handler iterate ~10⁹ times for that one name. A year-range check fixes this too.
Existing tests (routes.rs:2236-2259) cover only a valid date, garbage strings, and the epoch — no out-of-range component is tested.
Why it matters
Auto-backup names are generated (auto-2026-03-12T06:42:30.015Z), but tag names are user/peer-controlled data in a p2p store: a malformed or adversarial auto-… name is displayed and ordered as if it were a real backup from a different date (a "Feb 30" backup sorting as Mar 2, a 1969 backup claiming the epoch), and an absurd year can stall the file list. A parser that cannot represent a date should say so (None, which classify_tag already handles) rather than invent one.
Acceptance criteria
parse_iso_timestamp returns None for: month outside 1–12, day 0 or greater than the days in that month for that year (incl. Feb 29 on a non-leap year, Feb 30 always), hour > 23, minute > 59, second > 59.
Years before 1970 return None (the u64 result cannot represent them) instead of Some(0).
The year loop is bounded (the range check above suffices) — no per-year iteration for absurd years.
Valid inputs are unchanged: 2026-03-12T06:42:30.015Z → 1773297750, 1970-01-01T00:00:00Z → 0, Feb 29 on a leap year (e.g. 2024-02-29) parses correctly.
New unit tests next to the existing ones at routes.rs:2236+ cover each rejected class and the leap-day cases; existing test_classify_tag_* / test_parse_iso_timestamp_* tests still pass.
id train triage (2026-10-24): needs-decision — Muse: assign to Session A (phases 0-10 review); parse_iso_timestamp does no range validation (routes.rs:148-201).
Activity
dezren39 commentedon Oct 24, 2026
id train triage (2026-10-24): needs-decision — Muse: assign to Session A (phases 0-10 review); parse_iso_timestamp does no range validation (routes.rs:148-201).