]> Cypherpunks repositories - gostls13.git/commit
io/ioutil: don't cap buffer size in ReadFile
authorBryan C. Mills <bcmills@google.com>
Tue, 15 Aug 2017 19:08:39 +0000 (15:08 -0400)
committerBryan Mills <bcmills@google.com>
Thu, 31 Aug 2017 19:32:18 +0000 (19:32 +0000)
commit1d07ed15798b1228a2777c8ad80353b17a9ad8bd
treedeb20e59b30b21f2c9d0931d730a7cd45d655236
parentbf90da97c1aaec78d2f8ad8b74a506d3b6f0ee75
io/ioutil: don't cap buffer size in ReadFile

When we added a Stat call to determine the initial buffer size in
https://golang.org/cl/163069, we included an arbitrary 1e9-byte limit
"just in case". That interacts badly with power-of-2 resizing in
*bytes.Buffer: it causes buffers reading from very large files to
consume up to twice the necessary space.

The documentation for (os.FileInfo).Size says that it reports "length
in bytes for regular files; system-dependent for others", but the
"system dependent" cases overwhelmingly return either a small number
(e.g., the length of the target path for a symlink) or a non-positive
number (e.g., for a file in /proc under Linux). It should be
appropriate to use the number reported by Size as an approximate lower
bound, even if it is large.

fixes #21455

Change-Id: I609c72519b7b87428c24d0b22db46eede30e0e54
Reviewed-on: https://go-review.googlesource.com/55870
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/io/ioutil/ioutil.go