From: Joel Rosdahl Date: Sun, 27 Sep 2020 14:53:09 +0000 (+0200) Subject: Handle short read when writing result files X-Git-Tag: v4.0~62 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d53af3e59e1584cef4f0f6a82df536d00edaebf3;p=thirdparty%2Fccache.git Handle short read when writing result files Result::Write::write_embedded_file_entry assumes that read(2) never performs a “short read” (fewer bytes than the supplied count) for files. A short read can however happen if the process is interrupted by a signal, for instance on NFS with the “intr” mount option. Fix this by properly reducing the remaining bytes counter by the amount of actually read bytes. --- diff --git a/src/Result.cpp b/src/Result.cpp index 8af93fbb2..f0b89751b 100644 --- a/src/Result.cpp +++ b/src/Result.cpp @@ -382,8 +382,8 @@ Result::Writer::write_embedded_file_entry(CacheEntryWriter& writer, if (bytes_read == 0) { throw Error("Error reading from {}: end of file", path); } - writer.write(buf, n); - remain -= n; + writer.write(buf, bytes_read); + remain -= bytes_read; } }