Skip to content
Myr

Fix integer overflow in FuzzyMatchV2 guard on 32-bit builds

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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).

authored by Junegunn Choi · committed by Junegunn Choi · parent d4352a0 · Browse files · 1 file+1 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+1 added−1 removed

  • other:+1 added−1 removed

1 file+1 added−1 removed

modified:src/algo/algo.go+1 added-1 removed
441 unmodified lines
442 // Since O(nm) algorithm can be prohibitively expensive for large input,443 // we fall back to the greedy algorithm.444 // Also, we should not allow a very long pattern to avoid 16-bit integer445 // overflow in the score matrix. 1000 is a safe limit.446 if slab != nil && N*M > cap(slab.I16) || M > 1000 {446 if slab != nil && int64(N)*int64(M) > int64(cap(slab.I16)) || M > 1000 {447 return FuzzyMatchV1(caseSensitive, normalize, forward, input, pattern, withPos, slab)448 }449450 // Phase 1. Optimized search for ASCII string
580 unmodified lines