Skip to content

Potential fix for code scanning alert no. 4: Size computation for allocation may overflow#3

Draft
bsdrop wants to merge 1 commit into
mainfrom
alert-autofix-4
Draft

Potential fix for code scanning alert no. 4: Size computation for allocation may overflow#3
bsdrop wants to merge 1 commit into
mainfrom
alert-autofix-4

Conversation

@bsdrop
Copy link
Copy Markdown
Owner

@bsdrop bsdrop commented May 14, 2026

Potential fix for https://github.com/bsdrop/lafdb/security/code-scanning/4

Add an explicit overflow guard before computing combined capacity in buildModifiedEvents (internal/scraper/modified.go), and only perform len(oldMap)+len(newMap) after validating it cannot exceed int max. In Go, a clean approach is:

  • Compute oldLen := len(oldMap), newLen := len(newMap).
  • Guard with if oldLen > int(^uint(0)>>1)-newLen { return nil, fmt.Errorf("...") }.
  • Then use total := oldLen + newLen for both ids and seen preallocation.

This preserves behavior for normal inputs while preventing overflow panic/wraparound. No new dependency is needed; fmt is already imported in the shown file.

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

…ocation may overflow

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
if oldLen > maxInt-newLen {
return nil, fmt.Errorf("too many tracked items")
}
total := oldLen + newLen
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.

2 participants