erlang/otp — pull request #368 by mikpe (2014-05-14 14:59:23+00:00)
Title: Fix efile_openfile() to handle stat() failure

If the initial stat() fails then efile_openfile() will still proceed
to open() the file. If that succeeds and the caller passed a non-NULL
pSize, then it will copy bogus data from the statbuf into *pSize. This
has been observed to cause file:read_file/1 to return truncated file
data with no error indication.

The use case involved a large file system mounted via NFS, with some
directories containing large number of files, and NFS mount options
that allow the NFS client to return EIO if the NFS server does not
respond quickly enough. Depending on the caching state of the client
and server machines, a few stat() calls (fewer than 1 per 10 million)
would take long enough to trigger EIO errors, but subsequent open()
calls would succeed, and read_file/1 would return truncated data. This
sequence of events has been observed via "strace" on beam.smp.

Signed-off-by: Mikael Pettersson