mirror of https://github.com/k3s-io/k3s
Fix bug in json framer.
parent
3aadafd411
commit
11849e232e
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue