From 677f9232ba25927f98d625da6a8ac67081884263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=20=D0=94?= =?UTF-8?q?=D0=B0=D1=80=D0=BE=D0=BD=D1=8C?= Date: Sat, 14 Mar 2020 01:44:01 +0300 Subject: [PATCH] Fix bug Pagination throws 500 when etrying set large value page --- features/jsonapi/pagination.feature | 4 ++++ src/DataProvider/Pagination.php | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/features/jsonapi/pagination.feature b/features/jsonapi/pagination.feature index d07aacf3b48..e8176df72d8 100644 --- a/features/jsonapi/pagination.feature +++ b/features/jsonapi/pagination.feature @@ -36,3 +36,7 @@ Feature: JSON API pagination handling Scenario: Get an error when provided page number is not valid When I send a "GET" request to "/dummies?page[page]=0" Then the response status code should be 400 + + Scenario: Get an error when provided page number is too large + When I send a "GET" request to "/dummies?page[page]=9223372036854775807" + Then the response status code should be 400 diff --git a/src/DataProvider/Pagination.php b/src/DataProvider/Pagination.php index 8a9bc41b9cd..75eda223982 100644 --- a/src/DataProvider/Pagination.php +++ b/src/DataProvider/Pagination.php @@ -90,8 +90,14 @@ public function getOffset(string $resourceClass = null, string $operationName = if ($graphql && null !== ($last = $this->getParameterFromContext($context, 'last'))) { return ($offset = ($context['count'] ?? 0) - $last) < 0 ? 0 : $offset; } + + $offset = ($this->getPage($context) - 1) * $limit; + + if (!\is_int($offset)) { + throw new InvalidArgumentException('Page parameter is too large.'); + } - return ($this->getPage($context) - 1) * $limit; + return $offset; } /**