mirror of
https://github.com/golang/go
synced 2024-11-26 21:01:31 -07:00
runtime: check that new slice cap doesn't overflow
Fixes #7550. LGTM=iant R=golang-codereviews, iant, josharian CC=golang-codereviews https://golang.org/cl/83520043
This commit is contained in:
parent
568f50e3fc
commit
9121e7e4df
@ -65,7 +65,7 @@ func growslice(t *SliceType, old Slice, n int64) (ret Slice) {
|
||||
|
||||
cap = old.cap + n;
|
||||
|
||||
if((intgo)cap != cap || cap < old.cap || (t->elem->size > 0 && cap > MaxMem/t->elem->size))
|
||||
if((intgo)cap != cap || cap < (int64)old.cap || (t->elem->size > 0 && cap > MaxMem/t->elem->size))
|
||||
runtime·panicstring("growslice: cap out of range");
|
||||
|
||||
if(raceenabled) {
|
||||
|
27
test/fixedbugs/issue7550.go
Normal file
27
test/fixedbugs/issue7550.go
Normal file
@ -0,0 +1,27 @@
|
||||
// run
|
||||
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
func shouldPanic(f func()) {
|
||||
defer func() {
|
||||
if recover() == nil {
|
||||
panic("not panicking")
|
||||
}
|
||||
}()
|
||||
f()
|
||||
}
|
||||
|
||||
func f() {
|
||||
length := int(^uint(0) >> 1)
|
||||
a := make([]struct{}, length)
|
||||
b := make([]struct{}, length)
|
||||
_ = append(a, b...)
|
||||
}
|
||||
|
||||
func main() {
|
||||
shouldPanic(f)
|
||||
}
|
Loading…
Reference in New Issue
Block a user