Skip to content

Potential fix for code scanning alert no. 8: Slice memory allocation with excessive size value - #4

Draft
Pradyothsp wants to merge 1 commit into
mainfrom
alert-autofix-8
Draft

Pradyothsp wants to merge 1 commit into
mainfrom
alert-autofix-8

Conversation

@Pradyothsp

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/Pradyothsp/GoVec/security/code-scanning/8

The correct fix is to validate and cap user-controlled search size (k) at the API boundary before invoking engine/index/graph search. This preserves existing behavior for valid requests while rejecting abusive values early with 400 Bad Request.

Best single fix (without changing intended functionality):

  • In internal/api/handlers/vectors.go, inside VectorHandler.Search, add a maximum allowed k constant and reject values above it.
  • Keep the existing negative check; extend validation to k > maxK.
  • Return a clear bad-request error message when out of range.

This prevents tainted oversized values from ever flowing into fetchCount, resultCap, and slice capacity allocations.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…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>
@Pradyothsp

Copy link
Copy Markdown
Owner Author

We need to consider adding maxK to config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant