From 11849e232e16858842a0a7f84ccdc61fab74f191 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Wed, 4 May 2016 11:35:06 +0200 Subject: [PATCH] Fix bug in json framer. --- pkg/util/framer/framer.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/util/framer/framer.go b/pkg/util/framer/framer.go index 1e886e818f6..615d07de1cc 100644 --- a/pkg/util/framer/framer.go +++ b/pkg/util/framer/framer.go @@ -145,6 +145,7 @@ func (r *jsonFrameReader) Read(data []byte) (int, error) { // RawMessage#Unmarshal appends to data - we reset the slice down to 0 and will either see // data written to data, or be larger than data and a different array. + n := len(data) m := json.RawMessage(data[:0]) if err := r.decoder.Decode(&m); err != nil { return 0, err @@ -153,7 +154,7 @@ func (r *jsonFrameReader) Read(data []byte) (int, error) { // If capacity of data is less than length of the message, decoder will allocate a new slice // and set m to it, which means we need to copy the partial result back into data and preserve // the remaining result for subsequent reads. - if n := cap(data); len(m) > n { + if len(m) > n { data = append(data[0:0], m[:n]...) r.remaining = m[n:] return n, io.ErrShortBuffer