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/55870Reviewed-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>
Showing
Please register or sign in to comment