summaryrefslogtreecommitdiff
path: root/src/lib/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-12-19 23:10:34 +0000
committerCarl Hetherington <cth@carlh.net>2018-12-19 23:10:34 +0000
commit05d90a3edda9c1f5e7499f0ce7b6617fe46ac54d (patch)
tree40c6b693a9d89a2b4e7647f1bd2647cf2442b3e5 /src/lib/util.cc
parentd60fd90a6e13c727a05b629c8c4b93d4bf3b717b (diff)
Be more careful with fread in various places.v2.13.88
Diffstat (limited to 'src/lib/util.cc')
-rw-r--r--src/lib/util.cc17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 051a4bb25..5eba8d73a 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -444,7 +444,7 @@ digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
}
boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i]));
- fread (p, 1, this_time, f);
+ checked_fread (p, this_time, f, files[i]);
p += this_time;
to_do -= this_time;
fclose (f);
@@ -465,7 +465,7 @@ digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i]));
dcpomatic_fseek (f, -this_time, SEEK_END);
- fread (p, 1, this_time, f);
+ checked_fread (p, this_time, f, files[i]);
p += this_time;
to_do -= this_time;
fclose (f);
@@ -782,3 +782,16 @@ increment_eyes (Eyes e)
return EYES_LEFT;
}
+
+void
+checked_fread (void* ptr, size_t size, FILE* stream, boost::filesystem::path path)
+{
+ size_t N = fread (ptr, 1, size, stream);
+ if (N != size) {
+ if (ferror(stream)) {
+ throw FileError (String::compose("fread error %1", errno), path);
+ } else {
+ throw FileError ("Unexpected short read", path);
+ }
+ }
+}