Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some weird test cases #23

Open
mstevens opened this issue Dec 20, 2024 · 0 comments
Open

Some weird test cases #23

mstevens opened this issue Dec 20, 2024 · 0 comments

Comments

@mstevens
Copy link

Hi,

I was investigating some slow performance and found a couple of weird test cases which I don't think are my original problem but definitely are interesting:

func TestNullByteMatcher(t *testing.T) {
    fmt.Printf("\ntesting in simple case...\n")
    m := NewMatcher()
    words := []string{
        "she", "he", "her", "hers",
    }
    for i, word := range words {
        m.Insert([]byte(word), i)
    }
    m.Cedar().DumpGraph("trie.gv")
    m.Compile()
    m.DumpGraph("dfa.gv")
    seq := []byte("he\x000")
    fmt.Printf("searching %s\n", string(seq))
    resp := m.Match(seq)
    for resp.HasNext() {
        items := resp.NextMatchItem(seq)
        for _, itr := range items {
            key := m.Key(seq, itr)
            fmt.Printf("key:%s value:%d\n", key, itr.Value.(int))
        }
    }
    resp.Release()
}

Fails with:

--- FAIL: TestNullByteMatcher (0.00s)
panic: runtime error: index out of range [-1] [recovered]
	panic: runtime error: index out of range [-1]

goroutine 5 [running]:
testing.tRunner.func1.2({0x100ead7a0, 0x140000160d8})
	/usr/local/go/src/testing/testing.go:1632 +0x1bc
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1635 +0x334
panic({0x100ead7a0?, 0x140000160d8?})
	/usr/local/go/src/runtime/panic.go:785 +0x124
github.com/iohub/ahocorasick.(*Cedar).child(...)
	/Users/michaelstevens/ahocorasick/cedar.go:307
github.com/iohub/ahocorasick.(*Cedar).hasLabel(...)
	/Users/michaelstevens/ahocorasick/cedar.go:302
github.com/iohub/ahocorasick.(*Matcher).Match(0x1400002d940, {0x1400000e728, 0x4, 0xd?})
	/Users/michaelstevens/ahocorasick/acmatcher.go:158 +0x304
github.com/iohub/ahocorasick.TestNullByteMatcher(0x14000077380?)
	/Users/michaelstevens/ahocorasick/matcher_test.go:22 +0x234
testing.tRunner(0x14000077380, 0x100ebbe30)
	/usr/local/go/src/testing/testing.go:1690 +0xe4
created by testing.(*T).Run in goroutine 1
	/usr/local/go/src/testing/testing.go:1743 +0x314
exit status 2

and

func TestOneByte(t *testing.T) {
    m := NewMatcher()
    words := []string{
        "\x01",
    }
    for i, word := range words {
        m.Insert([]byte(word), i)
    }
    m.Compile()
    seq := []byte("\x01")
    resp := m.Match(seq)
    for resp.HasNext() {
        items := resp.NextMatchItem(seq)
        for _, itr := range items {
            key := m.Key(seq, itr)
            fmt.Printf("key:%s value:%d\n", key, itr.Value.(int))
        }
    }
    resp.Release()
}

seems to do an infinite loop in resp.NextMatchItem and the test never completes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant