aboutsummaryrefslogtreecommitdiff
path: root/src/bytes/buffer.go
diff options
context:
space:
mode:
authorAfanasev Stanislav <phpprogger@gmail.com>2017-10-03 22:40:28 +0300
committerJoe Tsai <thebrokentoaster@gmail.com>2017-10-06 06:49:40 +0000
commit07e36af7d6a34d2d70fa794dda44ad2b087c21e1 (patch)
tree3e312e26fcaa456bd16069483cd8897650853e6d /src/bytes/buffer.go
parent9005b220e495ee260230ccf00e54e85abd6df808 (diff)
downloadgo-07e36af7d6a34d2d70fa794dda44ad2b087c21e1.tar.xz
bytes: panic in ReadFrom with more information with negative Read counts
This is only to aid in human debugging, and for that reason we maintain a panic, and not return an error. Fixes #22097 Change-Id: If72e4d1e47ec9125ca7bc97d5fe4cedb7f76ae72 Reviewed-on: https://go-review.googlesource.com/67970 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/bytes/buffer.go')
-rw-r--r--src/bytes/buffer.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/bytes/buffer.go b/src/bytes/buffer.go
index 099e431a36..a99e64d1e8 100644
--- a/src/bytes/buffer.go
+++ b/src/bytes/buffer.go
@@ -41,6 +41,7 @@ const (
// ErrTooLarge is passed to panic if memory cannot be allocated to store data in a buffer.
var ErrTooLarge = errors.New("bytes.Buffer: too large")
+var errNegativeRead = errors.New("bytes.Buffer: reader returned negative count from Read")
const maxInt = int(^uint(0) >> 1)
@@ -198,6 +199,10 @@ func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error) {
for {
i := b.grow(MinRead)
m, e := r.Read(b.buf[i:cap(b.buf)])
+ if m < 0 {
+ panic(errNegativeRead)
+ }
+
b.buf = b.buf[:i+m]
n += int64(m)
if e == io.EOF {