From 60a5be1e659515b4974f0155bf64cfa172b2cc0b Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 28 Nov 2025 18:41:45 +0900 Subject: [PATCH] Do not allow very long queries in FuzzyMatchV2 Close #4608 --- src/algo/algo.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/algo/algo.go b/src/algo/algo.go index 1a015a3a..ebb07d3e 100644 --- a/src/algo/algo.go +++ b/src/algo/algo.go @@ -445,7 +445,9 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util. // Since O(nm) algorithm can be prohibitively expensive for large input, // we fall back to the greedy algorithm. - if slab != nil && N*M > cap(slab.I16) { + // Also, we should not allow a very long pattern to avoid 16-bit integer + // overflow in the score matrix. 1000 is a safe limit. + if slab != nil && N*M > cap(slab.I16) || M > 1000 { return FuzzyMatchV1(caseSensitive, normalize, forward, input, pattern, withPos, slab) }