From 1f1db1f856d7fb751d5ce9fdba316ee921868672 Mon Sep 17 00:00:00 2001 From: Pradyoth S P <56448288+Pradyothsp@users.noreply.github.com> Date: Mon, 5 Oct 2026 23:19:29 -0400 Subject: [PATCH] Potential fix for code scanning alert no. 8: Slice memory allocation with excessive size value I think, this needs to come from a config. Need to think more about this Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Pradyoth S P <56448288+Pradyothsp@users.noreply.github.com> --- internal/api/handlers/vectors.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/api/handlers/vectors.go b/internal/api/handlers/vectors.go index d283918..a8fadb0 100644 --- a/internal/api/handlers/vectors.go +++ b/internal/api/handlers/vectors.go @@ -176,6 +176,8 @@ func (h *VectorHandler) Insert(c *gin.Context) { // @Security BearerAuth // @Router /api/v1/vectors/search [post] func (h *VectorHandler) Search(c *gin.Context) { + const maxSearchK = 10000 + var req SearchRequest if err := c.ShouldBindJSON(&req); err != nil { response.Fail(c, http.StatusBadRequest, err.Error()) @@ -186,6 +188,10 @@ func (h *VectorHandler) Search(c *gin.Context) { response.Fail(c, http.StatusBadRequest, "k cannot be negative") return } + if *req.K > maxSearchK { + response.Fail(c, http.StatusBadRequest, "k exceeds maximum allowed value") + return + } results, err := h.Engine.Search(c.Request.Context(), req.Vector, sparseOrNone(req.SparseVector), *req.K, req.Filters) if err != nil {