mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
bytes: avoid overflow in (*Buffer).Grow and ReadFrom
fixes #21481 Change-Id: I26717876a1c0ee25a86c81159c6b3c59563dfec6 Reviewed-on: https://go-review.googlesource.com/56230 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
d9606e5532
commit
6a34ffa073
2 changed files with 25 additions and 4 deletions
|
|
@ -473,6 +473,18 @@ func TestGrow(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGrowOverflow(t *testing.T) {
|
||||
defer func() {
|
||||
if err := recover(); err != ErrTooLarge {
|
||||
t.Errorf("after too-large Grow, recover() = %v; want %v", err, ErrTooLarge)
|
||||
}
|
||||
}()
|
||||
|
||||
buf := NewBuffer(make([]byte, 1))
|
||||
const maxInt = int(^uint(0) >> 1)
|
||||
buf.Grow(maxInt)
|
||||
}
|
||||
|
||||
// Was a bug: used to give EOF reading empty slice at EOF.
|
||||
func TestReadEmptyAtEOF(t *testing.T) {
|
||||
b := new(Buffer)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue