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

String() crashes with an incomplete (?) ending byte #9

Open
codegoalie opened this issue Oct 21, 2017 · 2 comments · May be fixed by #10
Open

String() crashes with an incomplete (?) ending byte #9

codegoalie opened this issue Oct 21, 2017 · 2 comments · May be fixed by #10
Assignees
Labels

Comments

@codegoalie
Copy link
Collaborator

codegoalie commented Oct 21, 2017

Discovered adding fuzz tests with #8

Reproducing test:

func TestIncompleteLast(t *testing.T) {
    a := "00000000000000000000" +
        "00000000000000000000" +
        "00000000000000000000" +
        "000\xcb"

    r := New()
    if err := r.Insert(0, a); err != nil {
        t.Fatal(err)
    }

    assert.Equal(t, a, r.String())
}
--- FAIL: TestIncompleteLast (0.00s)
panic: runtime error: slice bounds out of range [recovered]
        panic: runtime error: slice bounds out of range

goroutine 11 [running]:
testing.tRunner.func1(0xc420102690)
        /home/codegoalie/workspace/sources/go/src/testing/testing.go:711 +0x2d2
panic(0x6f86c0, 0x94c330)
        /home/codegoalie/workspace/sources/go/src/runtime/panic.go:491 +0x283
github.com/codegoalie/skiprope.(*Rope).SubstrBytes(0xc420104900, 0x0, 0x40, 0x0, 0xc420299600, 0x40)
        /home/codegoalie/workspace/go/src/github.com/codegoalie/skiprope/rope.go:107 +0x3b0
github.com/codegoalie/skiprope.(*Rope).Substr(0xc420104900, 0x0, 0x40, 0x4e5b01, 0xc420104900)
        /home/codegoalie/workspace/go/src/github.com/codegoalie/skiprope/rope.go:121 +0x3f
github.com/codegoalie/skiprope.(*Rope).String(0xc420104900, 0x0, 0x75c744)
        /home/codegoalie/workspace/go/src/github.com/codegoalie/skiprope/rope.go:186 +0x3d
github.com/codegoalie/skiprope.TestIncompleteLast(0xc420102690)
        /home/codegoalie/workspace/go/src/github.com/codegoalie/skiprope/rope_test.go:212 +0x17d
testing.tRunner(0xc420102690, 0x764360)
        /home/codegoalie/workspace/sources/go/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
        /home/codegoalie/workspace/sources/go/src/testing/testing.go:789 +0x2de
exit status 2
FAIL    github.com/codegoalie/skiprope  0.011s
@codegoalie codegoalie changed the title String() crashes with an incomplete (?) ending byte String() crashes with an incomplete (?) ending byte Oct 21, 2017
@codegoalie codegoalie linked a pull request Oct 21, 2017 that will close this issue
@chewxy chewxy added the bug label Oct 21, 2017
@chewxy
Copy link
Owner

chewxy commented Oct 21, 2017

Looks like the reason is it's not calculating the length of bytes correctly. What do you think the fix should be?

@codegoalie
Copy link
Collaborator Author

Seems like we are getting Rope.runes from utf8.RuneCount which treats incorrect stuff as a single rune:

RuneCount returns the number of runes in p. Erroneous and short encodings are treated as single runes of width 1 byte.

Perhaps there are instances where we are counting runes when we should be counting bytes? I haven't been able to dig into much of the search.go code.

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

Successfully merging a pull request may close this issue.

2 participants