Open Fusl opened 1 year ago
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. https://github.com/json-iterator/go/blob/71ac16282d122fdd1e3a6d3e7f79b79b4cc3b50e/iter.go#L265-L279
WhatIsNext
item.buf
Iterator.Reset()
Iterator.loadMore()
.Read()
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.
iter.head
iter.tail
Reproduction code:
This would block forever in the
WhatIsNext
function because no internalitem.buf
was allocated duringIterator.Reset()
andIterator.loadMore()
will just endlessly try to fill the buffer here because the.Read()
call with a nil buffer will immediately return without reading anything. https://github.com/json-iterator/go/blob/71ac16282d122fdd1e3a6d3e7f79b79b4cc3b50e/iter.go#L265-L279The 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
anditer.tail
everywhere we're making use of it.