File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -228,6 +228,15 @@ public function search(Builder $builder)
228
228
*/
229
229
public function paginate (Builder $ builder , $ perPage , $ page )
230
230
{
231
+ $ maxInt = 4294967295 ;
232
+
233
+ $ page = max (1 , (int ) $ page );
234
+ $ perPage = max (1 , (int ) $ perPage );
235
+
236
+ if ($ page * $ perPage > $ maxInt ) {
237
+ $ page = floor ($ maxInt / $ perPage );
238
+ }
239
+
231
240
return $ this ->performSearch (
232
241
$ builder ,
233
242
$ this ->buildSearchParameters ($ builder , $ page , $ perPage )
Original file line number Diff line number Diff line change @@ -223,6 +223,21 @@ public function test_it_can_use_raw_cursor_search_with_after_raw_search_callback
223
223
$ this ->assertArrayHasKey ('search_time_ms ' , $ rawResults );
224
224
}
225
225
226
+ public function test_it_handles_pagination_with_max_int_overflow ()
227
+ {
228
+ $ maxInt = 4294967295 ;
229
+ $ perPage = 10 ;
230
+ $ overflowPage = 4294967296 ; // max int + 1
231
+ $ expectedPage = floor ($ maxInt / $ perPage );
232
+
233
+ $ results = SearchableUser::search ('lar ' )
234
+ ->paginate ($ perPage , $ overflowPage );
235
+
236
+ // Verify the page was adjusted correctly
237
+ $ this ->assertEquals ($ expectedPage , $ results ->currentPage ());
238
+ $ this ->assertEquals ($ perPage , $ results ->perPage ());
239
+ }
240
+
226
241
protected static function scoutDriver (): string
227
242
{
228
243
return 'typesense ' ;
You can’t perform that action at this time.
0 commit comments