Skip to content

id(web): file-list pagination multiplies raw page/per_page unchecked — overflow panics in debug, wrong page in release, per_page unbounded #931

Closed

Description

@dezren39

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 overflow at the start computation. 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 start to 0 and returns files 0..10 — page 3 silently returns page 1's files, while the response reports page=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_page is unbounded: ?per_page=100000000 defeats 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_page arithmetic cannot overflow or wrap for any query values: use checked/saturating arithmetic (an out-of-range page returns an empty page, with the requested page/per_page echoed as today).
  • per_page is clamped to a sane maximum (pick one, e.g. 200, and note it in the code near DEFAULT_PER_PAGE); page handling 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; a per_page above the new maximum; and the existing normal paging cases still pass.
  • Targeted test path: the existing routes.rs test 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

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Oct 26, 2026
  2. dezren39 commented on Oct 26, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job
    • Session / ID: new-issue-creator run, 2026-10-25 20:15 CDT (America/Chicago)
    • Found via: filed this run
    • Task: File-list pagination overflow (routes.rs:973-985) — verified with a standalone rustc probe replicating the exact arithmetic: debug panics on multiply overflow, release wraps and returns the wrong page; per_page unbounded. Queued for the code pilot queue (small_fix packet).
    • Expectation: effort/s — done looks like clamped per_page, saturating offset arithmetic, and regression tests for the overflow cases in the issue.
    • Links: n/a yet (queue packet enqueued this run)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus/needs-triageNot yet triaged; needs a first looktask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions