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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user