chiark / gitweb /
fileio: fix read_full_stream() bugs (#3887)
authorVito Caputo <vcaputo@gnugeneration.com>
Thu, 4 Aug 2016 20:52:02 +0000 (13:52 -0700)
committerSven Eden <yamakuzure@gmx.net>
Wed, 5 Jul 2017 06:50:50 +0000 (08:50 +0200)
commitd1dcbfbabb3ce13ceb0d5dd48a2478bce8d8ed21
tree0aaaf157017a1e27754e674880840a19e4893e14
parentd8f8fe03ac45bad693329c78dd71d4b1acc9df1b
fileio: fix read_full_stream() bugs (#3887)

read_full_stream() _always_ allocated twice the memory needed, due to
only breaking the realloc() && fread() loop when fread() returned 0,
requiring another iteration and exponentially enlarged buffer just to
discover the EOF condition.

This also caused file sizes >2MiB && <= 4MiB to erroneously be treated
as E2BIG, due to the inappropriately doubled buffer size exceeding
4*1024*1024.

Also made the 4*1024*1024 magic number a READ_FULL_BYTES_MAX constant.
src/basic/fileio.c