From 19c3b67cddc13ef549d98a6d76c996e0ec628f4d Mon Sep 17 00:00:00 2001 From: jamesread Date: Thu, 30 Oct 2025 00:12:06 +0000 Subject: [PATCH] fix: fix panic in pagination if we get a bad request --- service/internal/api/api.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/service/internal/api/api.go b/service/internal/api/api.go index 59d35f4..e934ddd 100644 --- a/service/internal/api/api.go +++ b/service/internal/api/api.go @@ -509,6 +509,20 @@ func (api *oliveTinAPI) GetActionLogs(ctx ctx.Context, req *connect.Request[apiv pageSize := api.cfg.LogHistoryPageSize startOffset := req.Msg.StartOffset + // Validate and clamp offset to prevent out-of-bounds access + if startOffset < 0 { + startOffset = 0 + } + + // If offset is beyond available data, return empty result with correct metadata + if startOffset >= totalCount { + ret.CountRemaining = 0 + ret.PageSize = pageSize + ret.TotalCount = totalCount + ret.StartOffset = startOffset + return connect.NewResponse(ret), nil + } + startIdx := startOffset endIdx := startOffset + pageSize if endIdx > totalCount {