mirror of
https://github.com/junegunn/fzf.git
synced 2026-05-25 17:58:50 +08:00
Fix integer overflow in FuzzyMatchV2 guard on 32-bit builds
On 32-bit platforms (GOARCH=386, arm), N*M overflows int when N is large and M approaches 1000, wrapping negative. The wrapped value slips past both `N*M > cap(slab.I16)` and `M > 1000`, so the V1 fallback is skipped and alloc16 panics on a negative slice bound. Cast to int64 before multiplying. Affects shipped 32-bit ARM builds (linux_armv5/6/7, windows_armv5/6/7). Reported with fix by Michal Majchrowicz and Marcin Wyczechowski (AFINE Team).
This commit is contained in:
+1
-1
@@ -443,7 +443,7 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util.
|
|||||||
// we fall back to the greedy algorithm.
|
// we fall back to the greedy algorithm.
|
||||||
// Also, we should not allow a very long pattern to avoid 16-bit integer
|
// Also, we should not allow a very long pattern to avoid 16-bit integer
|
||||||
// overflow in the score matrix. 1000 is a safe limit.
|
// overflow in the score matrix. 1000 is a safe limit.
|
||||||
if slab != nil && N*M > cap(slab.I16) || M > 1000 {
|
if slab != nil && int64(N)*int64(M) > int64(cap(slab.I16)) || M > 1000 {
|
||||||
return FuzzyMatchV1(caseSensitive, normalize, forward, input, pattern, withPos, slab)
|
return FuzzyMatchV1(caseSensitive, normalize, forward, input, pattern, withPos, slab)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user