Repository navigation
Description
Bug
id(web): the file-list pagination display arithmetic in render_file_list_content still multiplies the raw page number unchecked — the remainder of #931 that its fix did not cover.
pkgs/id/src/web/templates.rs:350 (main 1ff34134):
let start = (page.page - 1) * page.per_page + 1;
let end = (start + page.files.len()).saturating_sub(1);This runs whenever total_pages > 1 (templates.rs:339-340). The values reaching it are not bounded above:
paginate()inpkgs/id/src/web/routes.rs:934-946(the id(web): file-list pagination multiplies raw page/per_page unchecked — overflow panics in debug, wrong page in release, per_page unbounded #931 fix) clampsper_pageto1..=200and computes its own offset withsaturating_sub/saturating_mul— but it deliberately echoespageback unclamped (page.unwrap_or(1).max(1)), and its regression testtest_paginate_overflow_page(routes.rs:3104) assertspage == usize::MAXis returned for?page=18446744073709551615.get_file_list_pagepasses that echoedpagestraight intoFileListPage, which both/filesand/api/filesrender throughrender_file_list_content.
So a well-formed query such as /api/files?page=18446744073709551615&per_page=50 on any instance with more files than one page (e.g. 300 files) reaches line 350 with page = usize::MAX, per_page = 50, files = [].
Verified this run
Standalone rustc probe on the laptop replicating templates.rs:339-351 verbatim, fed exactly the values paginate() returns for that query (probe: hidden_files/probe-2026-10-27-laneB-templates-pagination/probe_tpl.rs, log out.log in the goal bookkeeping):
- Control (page 2, per_page 50, total 300, 50 files shown):
51-100 of 300 (page 2 / 6)— correct in both build modes. - Debug semantics (overflow checks on — the dev/test profiles;
pkgs/id/Cargo.tomlsets no overflow-checks override): panicattempt to multiply with overflowat thestartcomputation, exit 101. Through the real handler that is a panicked request task for/filesand/api/files. - Release semantics (overflow checks off): the range wraps to
18446744073709551517-18446744073709551516 of 300— an inverted, bogus range (start > end, both astronomically larger than the total) rendered as if it were the requested page's range. Withper_page=200(the clamp maximum):18446744073709551217-18446744073709551216 of 300.
Why it matters
#931 closed the wrong-page/panic hole in the offset computation, but the same untrusted page value still flows into a second unchecked multiplication in the renderer — so the exact class of bug #931 was filed for (debug panic / release wrong output from a crafted or buggy client query) is still reachable on the web UI's main listing endpoint. Wrong-range output is worse than an error: the UI presents it as the requested page's position.
Related: #931 (closed — fixed paginate() in routes.rs only; this filing is its renderer remainder, not a duplicate: different file, different arithmetic, still live on current main).
Acceptance criteria
- The pagination display arithmetic in
render_file_list_contentcannot overflow or wrap for anyFileListPagevalues: use saturating/checked arithmetic forstart(and audittotal_pagesat templates.rs:339 andendat :351 in the same pass). - For an out-of-range page, the rendered range is sane (e.g. an empty/clamped range that never shows start > end and never exceeds the total), while normal pages render exactly as today (
51-100 of 300for page 2 at per_page 50). - Regression tests cover at least:
page=usize::MAX, per_page=50, total=300, files=[];page=usize::MAX, per_page=200; and the existing normal paging display cases still pass. - Targeted test path: the existing templates/routes test modules (
cargo test --features web --lib web::templates/web::routes), run on CI or the laptop — not a sandbox build.
Suggested fix
In render_file_list_content (templates.rs:350-351), compute start as page.page.saturating_sub(1).saturating_mul(page.per_page).saturating_add(1) and clamp the displayed range to the total (an out-of-range page has files.is_empty(), so displaying 0-0 of {total} or suppressing the range is defensible — pick one and pin it in the test). Alternatively clamp page to total_pages in get_file_list_page — but note paginate()'s echo-the-requested-page behaviour is pinned by its existing test, so the renderer-side fix is the smaller change.
Single-repo: render_file_list_content is pkgs/id-local; no copy exists in the other three fleet repos.
Activity
developing-today commentedon Oct 27, 2026
CODE-546
dezren39 commentedon Oct 27, 2026
🤖 Agent note · filed
61 remaining items
dezren39 commentedon Oct 28, 2026
🤖 Agent note · picked up
fix(id): saturating pagination display arithmetic in templates.rs (#1633
dezren39 commentedon Oct 28, 2026
🤖 Agent note · done
c69b7426eb3d41dade69a5440d21f8b5f383d8bc) after fresh verification: all 32 checks pass at head cc59a35, PR MERGEABLE, single-file diff (templates.rs, saturating pagination display arithmetic + regression tests). Issue auto-closed by the merge.