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

allocate a 512 byte buffer if none exists during Iterator.Reset() #669

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Fusl
Copy link

@Fusl Fusl commented Mar 22, 2023

Reproduction code:

iter := jsoniter.NewIterator(jsoniter.ConfigDefault).Reset(r)
t := iter.WhatIsNext()

This would block forever in the WhatIsNext function because no internal item.buf was allocated during Iterator.Reset() and Iterator.loadMore() will just endlessly try to fill the buffer here because the .Read() call with a nil buffer will immediately return without reading anything.

go/iter.go

Lines 265 to 279 in 71ac162

for {
n, err := iter.reader.Read(iter.buf)
if n == 0 {
if err != nil {
if iter.Error == nil {
iter.Error = err
}
return false
}
} else {
iter.head = 0
iter.tail = n
return true
}
}

The change here is to just allocate a 512 byte buffer if there wasn't one defined before. I believe that it can be safely reused without having to clear it because we're working with the iter.head and iter.tail everywhere we're making use of it.

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.

1 participant