From 6832682204121ae4fa23569af65c43bbb9fd547d Mon Sep 17 00:00:00 2001 From: Nao Yonashiro Date: Fri, 18 Mar 2022 23:31:33 +0900 Subject: [PATCH] fix: mismatched between len(s.buf) and s.bufSize close #348 --- decode_test.go | 11 +++++++++++ internal/decoder/stream.go | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/decode_test.go b/decode_test.go index 209c658..f981178 100644 --- a/decode_test.go +++ b/decode_test.go @@ -3859,3 +3859,14 @@ func TestIssue337(t *testing.T) { t.Fatal("unexpected result", m) } } + +func TestIssue348(t *testing.T) { + in := strings.Repeat("["+strings.Repeat(",1000", 500)[1:]+"]", 2) + dec := json.NewDecoder(strings.NewReader(in)) + for dec.More() { + var foo interface{} + if err := dec.Decode(&foo); err != nil { + t.Error(err) + } + } +} diff --git a/internal/decoder/stream.go b/internal/decoder/stream.go index a33bec6..332d47d 100644 --- a/internal/decoder/stream.go +++ b/internal/decoder/stream.go @@ -103,7 +103,7 @@ func (s *Stream) statForRetry() ([]byte, int64, unsafe.Pointer) { func (s *Stream) Reset() { s.reset() - s.bufSize = initBufSize + s.bufSize = int64(len(s.buf)) } func (s *Stream) More() bool {