Repository navigation
Description
Bug
id(web): the file-list pagination in get_file_list_page computes the page offset with unchecked usize arithmetic on raw query parameters, and per_page has no upper bound.
pkgs/id/src/web/routes.rs:973-985 (on main 402b5aa):
let per_page = query.per_page.unwrap_or(DEFAULT_PER_PAGE).max(1);
let page = query.page.unwrap_or(1).max(1);
let start = (page - 1) * per_page;
let page_files = if start < total {
files[start..(start + per_page).min(total)].to_vec()
} else {
Vec::new()
};page / per_page come straight from the query string (FileListQuery, routes.rs:82-90, both Option<usize>, no clamping). pkgs/id/Cargo.toml sets no overflow-checks override, so the dev/test profiles panic on overflow and the release profile wraps.
Verified this run (standalone rustc probe replicating lines 973-985 verbatim)
- Debug semantics (overflow checks on, as in dev/test):
page=3, per_page=9223372036854775808 (2^63), total=10→ panic:attempt to multiply with overflowat thestartcomputation. Through the real handler that is a panicked request task for a well-formed query string. - Release semantics (overflow checks off): the same input wraps
startto0and returns files0..10— page 3 silently returns page 1's files, while the response reportspage=3, per_page=2^63. - Normal case sanity-checked with the same probe:
page=3, per_page=2, total=10→ slice end 6 (files 4..6), as expected. - Separately,
per_pageis unbounded:?per_page=100000000defeats pagination entirely and returns the whole filtered list in one response.
Why it matters
The file list is the web UI's main listing endpoint (used by both the page handler at routes.rs:346 and the JSON handler at routes.rs:700). A crafted or buggy client query can panic the request handler in debug/test builds and silently return the wrong page in release builds — wrong-page results are worse than an error, because the UI renders them as if they were the requested page. Unbounded per_page also removes the only size control on this response.
Acceptance criteria
page/per_pagearithmetic cannot overflow or wrap for any query values: use checked/saturating arithmetic (an out-of-range page returns an empty page, with the requestedpage/per_pageechoed as today).per_pageis clamped to a sane maximum (pick one, e.g. 200, and note it in the code nearDEFAULT_PER_PAGE);pagehandling for absurd values returns an empty page instead of wrapping.- Regression tests cover at least:
page=3, per_page=2^63;page=usize::MAX, per_page=50; aper_pageabove the new maximum; and the existing normal paging cases still pass. - Targeted test path: the existing
routes.rstest module / handler tests (cargo test --features web --lib web::routes), run on CI or the laptop — not a sandbox build.
Suggested fix
In get_file_list_page: clamp per_page with .clamp(1, MAX_PER_PAGE), compute start with page.saturating_sub(1).saturating_mul(per_page), and compute the slice end with start.saturating_add(per_page).min(total) (keeping the start < total guard).
Single-repo: the pattern was checked in this repo only for this filing; no copy of get_file_list_page exists in the other three fleet repos (it is pkgs/id-local code).
Activity
dezren39 commentedon Oct 26, 2026
🤖 Agent note · filed