From 55bc155f54dd5ece88abd142dafad113c2466da7 Mon Sep 17 00:00:00 2001 From: Michael Pursifull Date: Sun, 19 Apr 2026 00:41:52 -0500 Subject: [PATCH] Potential fix for code scanning alert no. 9: Size computation for allocation may overflow Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- internal/core/duplicate_detector.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/core/duplicate_detector.go b/internal/core/duplicate_detector.go index 2a2666a52..abebf0ce0 100644 --- a/internal/core/duplicate_detector.go +++ b/internal/core/duplicate_detector.go @@ -1,6 +1,7 @@ package core import ( + "math" "sort" "strings" ) @@ -26,6 +27,13 @@ func LevenshteinDistance(a, b string) int { if len(b) == 0 { return len(a) } + // Guard allocation arithmetic from integer overflow. + if len(b) > math.MaxInt-1 { + return len(b) + } + if len(a) > math.MaxInt-1 { + return len(a) + } // Use two rows instead of full matrix for space efficiency. prev := make([]int, len(b)+1)