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)