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:
@@ -160,9 +160,11 @@ func (s *Service) Export(ctx context.Context, dataset, delimiter string, page, p
|
||||
page = 1
|
||||
}
|
||||
out.Page = page
|
||||
start := (page - 1) * perPage
|
||||
if start > len(rows) {
|
||||
start = len(rows)
|
||||
// A page past the last is empty; compared before multiplying, so a
|
||||
// huge page cannot overflow into a negative start (WR-14).
|
||||
start := len(rows)
|
||||
if page <= out.Pages {
|
||||
start = (page - 1) * perPage
|
||||
}
|
||||
end := min(start+perPage, len(rows))
|
||||
rows = rows[start:end]
|
||||
|
||||
Reference in New Issue
Block a user