Skip to content

id(web): file-list pagination display still multiplies the raw page unchecked — debug panic / wrapped inverted range for page=usize::MAX (the #931 remainder in templates.rs) #1472

Closed

Description

@dezren39

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:

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.toml sets no overflow-checks override): panic attempt to multiply with overflow at the start computation, exit 101. Through the real handler that is a panicked request task for /files and /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. With per_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_content cannot overflow or wrap for any FileListPage values: use saturating/checked arithmetic for start (and audit total_pages at templates.rs:339 and end at :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 300 for 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

  1. developing-today commented on Oct 27, 2026

    @developing-today
    Contributor
  2. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    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 27, 2026
  3. dezren39 commented on Oct 27, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Oct 28, 2026
  5. 61 remaining items

  6. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    queue/claimedQueue worker lifecycle state
    and removed
    queue/claimedQueue worker lifecycle state
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Oct 28, 2026
  7. dezren39 commented on Oct 28, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  8. dezren39 commented on Oct 28, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

    • Agent: queue worker (repo-worker-code), Lane A shift
    • Session / ID: queue task 1753
    • Found via: queue claim (resume)
    • Task: Done — PR 1633 merged (squash 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.
    • Expectation: complete — no follow-up.
    • Links: PR fix(id): saturating pagination display arithmetic in templates.rs #1633
  9. removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    on Oct 28, 2026
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 job

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions