]> Cypherpunks repositories - gostls13.git/commit
runtime: avoid infinite loop in growslice
authorMartin Möhrmann <moehrmann@google.com>
Wed, 23 Aug 2017 07:05:29 +0000 (09:05 +0200)
committerMartin Möhrmann <moehrmann@google.com>
Thu, 24 Aug 2017 12:11:14 +0000 (12:11 +0000)
commitf3e0d143131dc318a173f4f5cc4e4b96de93318d
tree16167d7fb136e7055c5493c9e27fe7e7446a3897
parentf04d5836181dec3ec1b7e427607f02fa7a204a2d
runtime: avoid infinite loop in growslice

On 386 the below code triggered an infinite loop in growslice:
x = make([]byte, 1<<30-1, 1<<30-1)
x = append(x, x...)

Check for overflow when calculating the new slice capacity
and set the new capacity to the requested capacity when an overflow
is detected to avoid an infinite loop.

No automatic test added due to requiring to allocate 1GB of memory
on a 32bit plaform before use of append is able to trigger the
overflow check.

Fixes #21441

Change-Id: Ia871cc9f88479dacf2c7044531b233f83d2fcedf
Reviewed-on: https://go-review.googlesource.com/57950
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Marvin Stenger <marvin.stenger94@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/slice.go