Skip to content

Index out of range panic in FuzzyMatchV2 with very long matching pattern and text #4608

@Ori-Riaru

Description

@Ori-Riaru

Checklist

  • I have read through the manual page (man fzf)
  • I have searched through the existing issues
  • For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.67.0

OS

  • Linux
  • macOS
  • Windows
  • Etc.

Shell

  • bash
  • zsh
  • fish

Problem / Steps to reproduce

FuzzyMatchV2 panics with index out of range [-1639] when given a very long matching pattern and text.

package main

import (
	"fmt"
	"slices"
	"strings"
	"unicode"

	"github.com/junegunn/fzf/src/algo"
	"github.com/junegunn/fzf/src/util"
)

func main() {
	size := 1640
	longPattern := strings.Repeat("a", size)
	longText := strings.Repeat("a", size)
	
	runes := []rune(longPattern)
	chars := util.ToChars([]byte(longText))
	
	res, pos := algo.FuzzyMatchV2(slices.ContainsFunc(runes, unicode.IsUpper), true, true, &chars, runes, true, nil)

	fmt.Println(res.Score, len(*pos))
}
go run .
panic: runtime error: index out of range [-1639]

goroutine 1 [running]:
github.com/junegunn/fzf/src/algo.FuzzyMatchV2(0x0, 0x1, 0x1, 0xc0000bcee0, {0xc0000d6000, 0x668, 0x6a0}, 0x1, 0x0)
        /home/riaru/go/pkg/mod/github.com/junegunn/fzf@v0.67.0/src/algo/algo.go:625 +0x1cb0
main.main()
        /mnt/nfs/riaru/Projects/fzf-bug-report/main.go:21 +0x1ca
exit status 2

the code for the minimal example I created can be found here:

https://go.dev/play/p/gRq21-fe4oI
https://github.com/Ori-Riaru/fzf-bug-report

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions