fix: a huge export or list page answers an empty page instead of panicking (WR-14)

(page-1)*perPage overflowed for a large page and sliced out of range.
Export compares the page with the page count before multiplying, and the
list endpoints cap the page number.
This commit is contained in:
2026-10-27 15:33:21 +01:00
parent c2ba33ee94
commit 59c37a8fea
3 changed files with 22 additions and 4 deletions

View File

@@ -184,10 +184,12 @@ func read(ctx context.Context, svc *classes.Service) (*gorm.DB, error) {
return svc.DB(ctx)
}
// The page sizes of the list endpoints.
// The page sizes of the list endpoints, and the highest page number read
// (a later page is empty anyway).
const (
defaultPerPage = 50
maxPerPage = 200
maxPage = 1_000_000
)
// ListInput is the paging and search query every list tool shares.
@@ -206,6 +208,10 @@ func listParams(r *http.Request) ListInput {
if in.Page < 1 {
in.Page = 1
}
// (Page-1)*PerPage must not overflow into a negative offset (WR-14).
if in.Page > maxPage {
in.Page = maxPage
}
if in.PerPage < 1 {
in.PerPage = defaultPerPage
}