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

fix iterator traversal empty object panic #314

Merged
merged 1 commit into from Oct 18, 2022

Conversation

linuxsong
Copy link
Contributor

Traversal a empty object with HasNext() will cause a panic.
Reproduce bug, in ast/iterator_test.go

str, _ := getTestIteratorSample(0)
root, err := NewParser(str).Parse()
if err != 0 {
    t.Fatal(err)
}
mi, _ := root.Get("object").Properties()
if mi.HasNext() {
    t.Fatalf("should not have next")
}





panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x143bf91]

goroutine 8 [running]:
testing.tRunner.func1.2({0x14af1a0, 0x189a320})
    /usr/local/Cellar/go/1.19.1/libexec/src/testing/testing.go:1396 +0x24e
testing.tRunner.func1()
    /usr/local/Cellar/go/1.19.1/libexec/src/testing/testing.go:1399 +0x39f
panic({0x14af1a0, 0x189a320})
    /usr/local/Cellar/go/1.19.1/libexec/src/runtime/panic.go:884 +0x212
github.com/bytedance/sonic/ast.(*Iterator).HasNext(0xc000004cb8?)
    /Users/xks/gitproject/sonic/ast/iterator.go:70 +0x51
github.com/bytedance/sonic/ast.TestIterator(0xc0002ae680)
    /Users/xks/gitproject/sonic/ast/iterator_test.go:205 +0x937
testing.tRunner(0xc0002ae680, 0x15506c0)
    /usr/local/Cellar/go/1.19.1/libexec/src/testing/testing.go:1446 +0x10b
created by testing.(*T).Run
    /usr/local/Cellar/go/1.19.1/libexec/src/testing/testing.go:1493 +0x35f

Copy link
Collaborator

@AsterDY AsterDY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AsterDY AsterDY merged commit 3e6f839 into bytedance:main Oct 18, 2022
@linuxsong linuxsong deleted the bugfix/iterator_panic branch October 21, 2022 08:23
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

Successfully merging this pull request may close these issues.

None yet

2 participants