mirror of
https://github.com/golang/go
synced 2024-11-20 04:44:40 -07:00
fmt, encoding/gob: fix misuse of Read
reader.Read() can return both 0,nil and len(buf),err. To be safe, we use io.ReadFull instead of doing reader.Read directly. Fixes #3472. R=bradfitz, rsc, ality CC=golang-dev https://golang.org/cl/6285050
This commit is contained in:
parent
2ad6714793
commit
5a2c275be1
@ -62,15 +62,15 @@ func overflow(name string) error {
|
||||
// Used only by the Decoder to read the message length.
|
||||
func decodeUintReader(r io.Reader, buf []byte) (x uint64, width int, err error) {
|
||||
width = 1
|
||||
_, err = r.Read(buf[0:width])
|
||||
if err != nil {
|
||||
n, err := io.ReadFull(r, buf[0:width])
|
||||
if n == 0 {
|
||||
return
|
||||
}
|
||||
b := buf[0]
|
||||
if b <= 0x7f {
|
||||
return uint64(b), width, nil
|
||||
}
|
||||
n := -int(int8(b))
|
||||
n = -int(int8(b))
|
||||
if n > uint64Size {
|
||||
err = errBadUint
|
||||
return
|
||||
|
@ -337,7 +337,10 @@ func (r *readRune) readByte() (b byte, err error) {
|
||||
r.pending--
|
||||
return
|
||||
}
|
||||
_, err = r.reader.Read(r.pendBuf[0:1])
|
||||
n, err := io.ReadFull(r.reader, r.pendBuf[0:1])
|
||||
if n != 1 {
|
||||
return 0, err
|
||||
}
|
||||
return r.pendBuf[0], err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user