]> Cypherpunks repositories - gostls13.git/commit
runtime: protect growslice against newcap*et.size overflow
authorMartin Möhrmann <moehrmann@google.com>
Sat, 12 Aug 2017 15:37:13 +0000 (17:37 +0200)
committerMartin Möhrmann <moehrmann@google.com>
Wed, 1 Nov 2017 12:38:02 +0000 (12:38 +0000)
commit371a5b494a7a0cb246a86e849b66ed022ef30c74
tree11e0f174b116f5a5690f1b9b67f25a5bedc21f04
parent96c62b3b318403261c09826a27f5b58ef9f40be8
runtime: protect growslice against newcap*et.size overflow

The check of uintptr(newcap) > maxSliceCap(et.size) in addition
to capmem > _MaxMem is needed to prevent a reproducible overflow
on 32bit architectures.

On 64bit platforms this problem is less likely to occur as allocation
of a sufficiently large array or slice to be append is likely to
already exhaust available memory before the call to append can be made.

Example program that without the fix in this CL does segfault on 386:

type T [1<<27 + 1]int64

var d T
var s []T

func main() {
        s = append(s, d, d, d, d)
        print(len(s), "\n")
}

Fixes #21586

Change-Id: Ib4185435826ef43df71ba0f789e19f5bf9a347e6
Reviewed-on: https://go-review.googlesource.com/55133
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/slice.go