mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Fix bug in json framer.
This commit is contained in:
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
|
// 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.
|
// data written to data, or be larger than data and a different array.
|
||||||
|
n := len(data)
|
||||||
m := json.RawMessage(data[:0])
|
m := json.RawMessage(data[:0])
|
||||||
if err := r.decoder.Decode(&m); err != nil {
|
if err := r.decoder.Decode(&m); err != nil {
|
||||||
return 0, err
|
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
|
// 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
|
// 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.
|
// the remaining result for subsequent reads.
|
||||||
if n := cap(data); len(m) > n {
|
if len(m) > n {
|
||||||
data = append(data[0:0], m[:n]...)
|
data = append(data[0:0], m[:n]...)
|
||||||
r.remaining = m[n:]
|
r.remaining = m[n:]
|
||||||
return n, io.ErrShortBuffer
|
return n, io.ErrShortBuffer
|
||||||
|
Loading…
Reference in New Issue
Block a user